Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_RenderDrawLine(s) not drawing 1 pixel line #2006

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 2 comments
Closed

SDL_RenderDrawLine(s) not drawing 1 pixel line #2006

SDLBugzilla opened this issue Feb 11, 2021 · 2 comments
Assignees
Milestone

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.3
Reported for operating system, platform: Windows 7, x86_64

Comments on the original bug report:

On 2015-11-02 17:26:00 +0000, Marcel Bakker wrote:

windows 7 + opengl is ok
windows 7 + directx is ok
windows 7 + software does not draw the line
debian(VM) + opengl does not draw the line
debian(VM) + software does not draw the line

I think this is a Software renderer bug
, and suspect the debian + opengl is another problem, maybe https://bugzilla.libsdl.org/show_bug.cgi?id=2796
(i have other missing pixels with debian + opengl)

Reproduce :
...
SDL_SetHint( SDL_HINT_RENDER_DRIVER, "software");
...
SDL_Point line_1pixel[2] = {{ 10, 10}, {10, 10}};
SDL_RenderDrawLines( render, line_1pixel, 2);

On 2017-10-18 14:52:30 +0000, Sylvain wrote:

*** Bug 3600 has been marked as a duplicate of this bug. ***

On 2017-10-18 14:53:57 +0000, Sylvain wrote:

Created attachment 3005
testcase

I have checked with a testcase:

opengl :

  • does not draw lines when there are 1 pixel.
  • can miss corner points. more than 2, it can miss N points.

opengles2 :

  • can miss corner points. more than 2, it can miss N points.

software renderer :

  • does not draw lines when there are 1 pixel.

you can also build a line of 1 point by using :
SDL_Point points[] = {{20, 20}, {20, 20}, {20, 20}, {20, 20}};
and then, opengles2 also misses to draw the pixel !

I Suggest the following solution:

  • SDL_DrawLines (SDL_DrawLine and SDL_DrawRect) should redirect to SDL_DrawPoints when line are 1 pixel.

  • Remove all corner-case code that try to add points at the end of lines, because it's just wrong. so let the driver decides to draw the points or not.

eventually,
in addition to SDL_DrawLines(points), proceed to a SDL_DrawPoints(points) to make sure the point are drawn.

or we can also modify each renderer to always draws vertices, in addition to the lines.

On 2017-10-18 14:59:17 +0000, Sylvain wrote:

Created attachment 3006
patch

here's a patch with previous things.
but it can be also written so that drawing all vertices is done in each renderer code.

On 2017-10-18 15:11:15 +0000, Sylvain wrote:

Created attachment 3007
patch

the patch, drawing the vertices can be optional

On 2017-10-18 15:16:09 +0000, Sam Lantinga wrote:

The problem is that some renderers will draw the vertices, depending on the driver, so we'll get double draw of those points, which isn't what we want in the case where there are blend modes applied.

The right solution is to switch line drawing to use textures, which is incredibly fast on modern graphics hardware, and can be pixel perfect.

On 2017-10-18 21:15:56 +0000, Sam Lantinga wrote:

*** Bug 3600 has been marked as a duplicate of this bug. ***

On 2017-10-18 21:23:22 +0000, Sylvain wrote:

Can you precise what you mean ?

I quickly tried to use a 1D texture with glTexImage1D(), and it still have the same behavior:

  • doesn't draw 1 pixel lines / misses sometimes vertices and extremities (if I remove the code that explicitly does it).

I also switched the GL_LINE_STRIP to GL_TRIANGLE_STRIP. Drawing is incorrect of course, but it shows also that vertices are still not drawn.

@icculus icculus self-assigned this Aug 12, 2021
@icculus icculus added this to the 2.0.18 milestone Aug 12, 2021
icculus added a commit that referenced this issue Sep 19, 2021
…derer.

One place known to differ in a significant way is a single line segment that
starts and ends on the same point; the GL renderers will light up a single
pixel here, whereas the software renderer will not. My current belief is this
is a bug in the software renderer, based on the wording of the docs:

"SDL_RenderDrawLine() draws the line to include both end points."

You can see an example program that triggers that difference in Bug #2006.

As it stands, the GL renderers might _also_ render diagonal lines differently,
as the the Bresenham step might vary between implementations (one does three
pixels and then two, the other does two and then three, etc). But this patch
causes those lines to start and end on the correct pixel, and that's the best
we can do, and all anyone really needs here.

Not closing any bugs with this patch (yet!), but here are several that it
appears to fix. If no other corner cases pop up, we'll call this done.

Reference Bug #2006.
Reference Bug #1626.
Reference Bug #4001.
...and probably others...
@icculus
Copy link
Collaborator

icculus commented Sep 19, 2021

(The single-point line rendering in OpenGL but not software is, imho, a software renderer bug, but the rest of the lines in that test case should now match up end points between the GL/GLES renderers and software.)

OpenGL and GLES renderers should be improved here, in the latest in revision control. Any corner cases that remain (or are caused by this patch), PLEASE report them asap, as we would like this to be solid and never thought about again by the time 2.0.18 ships.

Thanks!

icculus added a commit that referenced this issue Nov 26, 2021
Otherwise it would drop it, which seems like a bug to me, as it normally
fills the endpoint on lines.

Reference #2006.
@icculus
Copy link
Collaborator

icculus commented Nov 27, 2021

okay, I fixed the software renderer to match the other renderers (which is usually backwards from how we do it, but in this case I'm convinced this was a software renderer bug).

Closing this with several other bugs.

@icculus icculus closed this as completed Nov 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants