drawLine bugs with different display-scales, line-widths and caps

While developing a game that uses the drawing API (Lua) I noticed that diagonal lines have some rendering issues.

For my test case I rendered some 45 degree lines with the following line widths:
0.25, 0.5, 1, 2, 3, 4

All lines with Thickness 0.25 have an overdraw issue (marked green in the images), which might be related to: C API: `drawLine` API can "overdraw" by one pixel

All lines with Thickness 2 and lineCapStyle set to kLineCapStyleSquare seem to have a rendering bug (marked red in the images)

Line thickness 2 and 3 render weird line caps when set to kLineCapStyleRound (marked blue)

Here are the screenshots, line widths top line: 0.25, 0.5, 1 and second line: 2, 3, 4

1x-butt

1x-round

1x-square

2x-butt

2x-round

2x-square

4x-butt

4x-round

4x-square

And here's a PDX to test (Press A to cycle tests):
LineStyle.pdx.zip (3.2 KB)

4 Likes

Is there any update on this?

I'm currently running into these sorts of line-drawing bugs myself (in the C API) and even though I really, really don't want to, I'm considering taking the plunge and writing my own line rasterizer just to overcome them...

Ew, no good. :frowning: Thanks for waking this thread up, I must have missed it the first time around. I've got a fix for Jaggies with drawLine but it only fixes the glitches in the green circles. I'll add these to the issue, hopefully get a fix out soon.

1 Like

Oh, that's great! Does that fix cover the linked bug report in OP, too?

Also, using pd->graphics->drawLine() with width=0 vs. width=1 specifically documented anywhere? What's the difference supposed to be? Aside from some of these endpoint issues, width=0 looks more like a standard one-pixel line to me...

Nope, looks like that linked issue is still there. But I've got all three linked in the issue, so I'll sort them all out. I probably won't include Line with 2px width rasterizes to 1px width in this because I think it's an entirely different problem.

1 Like

Awesome! If I don't have to write a line rasterizer from scratch to get perfectly-drawn pixel lines from the C API that will be just fantastic—I'd much rather work on just about anything but that. Thank you!