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 783 - co-ordinate positioning incorrect with gl renderer
Summary: co-ordinate positioning incorrect with gl renderer
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: All Windows (XP)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-19 02:47 UTC by Mark.Howson
Modified: 2009-09-28 08:37 UTC (History)
1 user (show)

See Also:


Attachments
Due commit r4722 image slightly off down on testoverlay2 with white stripe above at MacOSX (33.00 KB, image/png)
2009-09-28 04:23 UTC, Adam Strzelecki
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark.Howson 2009-08-19 02:47:47 UTC
Using the opengl renderer on SVN 1.3 r4683, I find that pixel positioning is slightly off for rendering primitives. For example, the top visible pixel here is (0,1) : SDL_RenderPoint(0, 0) is not visible.

This also affects line primitives : SDL_RenderLine(30, 2, 40, 2) draws a line '2' pixels thick, rather than the 1 that might be expected.

I think these is due to opengl pixel positioning. I'm not sure if this is the most 'correct' fix, but here I've changed:

video/SDL_renderer_gl.c line 452-ish:

data->glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0,
                      0.0, 1.0);

to:

data->glOrtho(-0.5, (GLdouble) window->w-0.5, (GLdouble) window->h-0.5, -0.5,  0.0, 1.0);

With this pixels on line 0 and window->h-1 appear correctly. Thanks for reading.
Comment 1 Sam Lantinga 2009-09-18 22:12:51 UTC
Thanks!  This is fixed with revision 4722
Comment 2 Adam Strzelecki 2009-09-28 04:23:49 UTC
Created attachment 378 [details]
Due commit r4722 image slightly off down on testoverlay2 with white stripe above at MacOSX
Comment 3 Adam Strzelecki 2009-09-28 05:15:33 UTC
Regression!!
----------
Commit r4722 causes the image in testoverlay2 or drawlines2 to be shifted down and having a random junk strip above (see attached screenshot).

This is very ugly hack and with most of OpenGL manuals you need to set:

glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0, 0.0, 1.0);

to have pixel accuracy, so the code was OK before the change. -0.5 hack is IMHO unacceptable here.

The bug author/originator probably uses glEnable(GL_LINE_SMOOTH) & glEnable(GL_POINT_SMOOTH) which causes described 2-pixel thick lines on some graphic drivers. GL_LINE_SMOOTH is known to be quite driver-dependent and sluggish.

For the sake of exact coordinate mapping please rollback this fix. Lines are mapped exactly when GL_LINE_SMOOTH (default SDL behavior).

Feedback
-------
The bug author should first specify exactly the context of this bug, which OpenGL implementation he uses (OS?) and whether he uses custom OpenGL settings (via glParameter, glHint or glEnable).
Comment 4 Adam Strzelecki 2009-09-28 05:17:40 UTC
> For the sake of exact coordinate mapping please rollback this fix. Lines are
> mapped exactly when GL_LINE_SMOOTH (default SDL behavior).

I meant that lines are mapped OK with previous glOrtho code when GL_LINE_SMOOTH are OFF which is default SDL and OpenGL state, so -0.5 is just causing trouble here.
Comment 5 Sam Lantinga 2009-09-28 08:34:09 UTC
Okay, I left GL_LINE_SMOOTH off and reverted the -0.5 pixel offset.

Can you retest this bug?
Comment 6 Adam Strzelecki 2009-09-28 08:36:51 UTC
I have the r4722 reverted in my SVN and I can confirm everything is fine then (no junky stripe above).