We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3162

Summary: SDL_RenderDrawLine(s) not drawing 1 pixel line
Product: SDL Reporter: Marcel Bakker <mna.bakker>
Component: renderAssignee: Ryan C. Gordon <icculus>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: rtrussell, sylvain.becker
Version: 2.0.3   
Hardware: x86_64   
OS: Windows 7   
Attachments: testcase
patch
patch

Description Marcel Bakker 2015-11-02 17:26:00 UTC
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);
Comment 1 Sylvain 2017-10-18 14:52:30 UTC
*** Bug 3600 has been marked as a duplicate of this bug. ***
Comment 2 Sylvain 2017-10-18 14:53:57 UTC
Created attachment 3005 [details]
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.
Comment 3 Sylvain 2017-10-18 14:59:17 UTC
Created attachment 3006 [details]
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.
Comment 4 Sylvain 2017-10-18 15:11:15 UTC
Created attachment 3007 [details]
patch

the patch, drawing the vertices can be optional
Comment 5 Sam Lantinga 2017-10-18 15:16:09 UTC
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.
Comment 6 Sam Lantinga 2017-10-18 21:15:56 UTC
*** Bug 3600 has been marked as a duplicate of this bug. ***
Comment 7 Sylvain 2017-10-18 21:23:22 UTC
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.