SDL_RenderDrawLine endpoint inconsistency

my guess is that a badly defined rounding float -> int is used somewhere

this looks more difficult than what I thought; the openGL spec says explicitly that line segment rasterization need not be 1-pixel exact! See https://www.khronos.org/registry/OpenGL/specs/gl/glspec15.pdf, page 91:

“The coordinates of a fragment produced by the algorithm may not deviate by more than one unit in either x or y window coordinates from a corresponding fragment produced by the diamond-exit rule”

While this seems ok for intermediate pixels, this seems completely silly for end-points, especially when these have integer coordinates.

Another difficulty is that the openGL line segment algorithm will not draw the last pixel (in order for it not to be repeated when a sequence of line segments are drawn). SDL’s solution to this is to make the last segment one pixel longer. So probably the bug comes from there. Not sure, but I don’t have time to investigate more today…

I feared as much. Empirically, SDL2 seems to be able to plot individual pixels correctly (SDL_RenderDrawPoints() has always worked for me) so maybe the most reliable approach would be for it to draw horizontal and vertical lines that way internally. With the batching mechanism, it might not hit performance too much.

Can you try the latest in revision control and see if it fixes this issue for you? I made a fix that should resolve this, but this all feels like it has a million corner cases.

1 Like

at least the code above now works as expected for me! thanks!

I will test my more elaborate graphics routines when I get the time

So on current tip i get this


This is also what is breaking rects SDL_RenderDrawRect not rectangular · Issue #4001 · libsdl-org/SDL · GitHub

Reverting opengl: More work on making line drawing match software renderer. · libsdl-org/SDL@b99543b · GitHub fixes this, but since @Sanette had issues with that version…??

For cross-reference purposes: SDL_RenderDrawRect function broken