|
|
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Single Pixel Wide Straight Lines
Single Pixel Wide Straight Lines [message #59012] |
Fri, 14 October 2022 16:15 |
devilsclaw
Messages: 72 Registered: August 2022
|
Member |
|
|
So if I use Draw directly from the Paint function parameter I can draw Straight lines that are a single pixel wide.
If I use PaintingPainter, ImageBuffer BufferPainter combo, or DrawPainter Nearly all lines that are supposed to be single pixel wide are two pixels with fading effects applied to them. this is with MODE_ANTIALIASED, MODE_NOAA, MODE_SUBPIXEL as well. The reason why I say nearly all is because in some cases when I do a grid some lines are actually single lines but most are not.
The reason I can;t just use Draw is because I need the ability to draw in the same place twice and have them show both sort of mixed together.
Is there a way to draw single pixel wide straight lines or is there a way to paint pixels in an array or buffer or something so I can do that my self.
|
|
|
|
|
Re: Single Pixel Wide Straight Lines [message #59015 is a reply to message #59012] |
Fri, 14 October 2022 19:55 |
|
Hi devilsclaw,
It looks like you're actually drawing single pixel lines that do not "fit in the pixel". The engine actually draws half of it into one pixel and the other half to the adjacent one... This is not usually a problem, but it produces ugly results for vertical and horizontal lines. Try moving the horizontal lines 0.5 pixel up or down and similarly vertical lines 0.5px left or right
The only weird thing is that it does produce fuzzy effect even with NO_AA. I'd expect that without antialiasing, the coordinates would be rounded to the nearest pixel.
Best regards,
Honza
|
|
|
|
|
Re: Single Pixel Wide Straight Lines [message #59019 is a reply to message #59012] |
Fri, 14 October 2022 23:33 |
devilsclaw
Messages: 72 Registered: August 2022
|
Member |
|
|
So I figured out what is going on. Lines are painted from the center / origin of the point so if you say line is at y coord 10 and have a line width of 3 it will be 1.5 pixels below and above instead of starting the line at 10 and having 3 lines going down from the starting point.
This means all odd line sizes as in 1,2,5,7,9 etc will be the incorrect size with any integer based drawing on everything except Draw its self it seems. I believe this is the wrong way to draw a line it should not be center radial.
This code example shows it working and clean lines
void Paint(Draw &w) {
Size sz = GetSize();
ImageBuffer ib(sz);
BufferPainter sw(ib, MODE_ANTIALIASED);
sw.DrawRect(sz, Black());
int pos_y = 0;
for(int stroke = 1; true; stroke += 1) {
double center_of_line = stroke / 2.0;
sw.Move( 0, pos_y + center_of_line).Line(sz.cx, pos_y + center_of_line).Stroke(stroke, Red());
pos_y += (stroke * 2);
if(pos_y >= sz.cy) {
break;
}
}
}
[Updated on: Fri, 14 October 2022 23:35] Report message to a moderator
|
|
|
Re: Single Pixel Wide Straight Lines [message #59020 is a reply to message #59012] |
Fri, 14 October 2022 23:58 |
devilsclaw
Messages: 72 Registered: August 2022
|
Member |
|
|
To fix the below I ended up doing this.
void DrawLine(BufferPainter* bp, int x1, int y1, int x2, int y2, double stroke, Color color) {
double center_of_line_x = 0;
double center_of_line_y = 0;
if(x1 == x2) {
center_of_line_x = stroke / 2.0;
}
if(y1 == y2) {
center_of_line_y = stroke / 2.0;
}
bp->Move(x1 + center_of_line_x, y1 + center_of_line_y).Line(x2 + center_of_line_x, y2 + center_of_line_y).Stroke(stroke, color);
}
|
|
|
|
|
Re: Single Pixel Wide Straight Lines [message #59337 is a reply to message #59331] |
Sat, 17 December 2022 16:19 |
devilsclaw
Messages: 72 Registered: August 2022
|
Member |
|
|
Actually that would not work as you think since the problem is that that lines are drawn from there radial center and if you just shift everything by .5 then the even number lines will be messed up like the current odd line are. sure if the line is old then shift by 0.5 might be easier.
|
|
|
Goto Forum:
Current Time: Sun Oct 13 03:10:46 CEST 2024
Total time taken to generate the page: 0.03359 seconds
|
|
|