From 0c8bb3932210070f70d636e3b8bba44fe7b59d82 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 21 Nov 2009 07:14:21 +0000 Subject: [PATCH] This is terrible, but the OpenGL standard says that lines are half open, which means that one endpoint is not covered so adjoining lines don't overlap. It also doesn't define which end is open, and indeed Mac OS X and Linux differ. Mac OS X seems to leave the second endpoint open, but Linux uses the right-most endpoint for x major lines and the bottom-most endpoint for y major lines. --HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404214 --- src/video/SDL_renderer_gl.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/video/SDL_renderer_gl.c b/src/video/SDL_renderer_gl.c index cfd970f9c..84ddf7bf1 100644 --- a/src/video/SDL_renderer_gl.c +++ b/src/video/SDL_renderer_gl.c @@ -1150,22 +1150,20 @@ GL_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) (GLfloat) renderer->b * inv255f, (GLfloat) renderer->a * inv255f); + /* The line is half open, so we need tiny segments at the endpoints + * so that we guarantee coverage of the beginning and final pixels. + * http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html + */ data->glBegin(GL_LINES); + /* Ensure coverage of the first point */ + data->glVertex2f(0.1f + x1, 0.1f + y1); + data->glVertex2f(0.5f + x1, 0.5f + y1); + /* Draw the requested line */ data->glVertex2f(0.5f + x1, 0.5f + y1); data->glVertex2f(0.5f + x2, 0.5f + y2); - data->glEnd(); - - /* For some reason the rightmost or lowest endpoint is skipped */ - data->glBegin(GL_POINTS); - if (x1 > x2) { - data->glVertex2f(0.5f + x1, 0.5f + y1); - } else if (x2 > x1) { - data->glVertex2f(0.5f + x2, 0.5f + y2); - } else if (y1 > y2) { - data->glVertex2f(0.5f + x1, 0.5f + y1); - } else if (y2 > y1) { - data->glVertex2f(0.5f + x2, 0.5f + y2); - } + /* Ensure coverage of the second point */ + data->glVertex2f(0.5f + x2, 0.5f + y2); + data->glVertex2f(0.9f + x2, 0.9f + y2); data->glEnd(); return 0;