lo peeps. im using opengl to do some 2D stuff.
The thing thats been keeping me busy all day is the way to properly map the screen x,y coordinates to the sprites displayed onscreen.
Everytime I thought I got it right, the whole viewport seemed to be offset by 5-10 pixels in some direction, making the positioning of sprites a pain in the ass.
I just figured out that passing that offset to the glOrtho command 'fixes' the problem.
just using: glOrtho( 0, obj.StageWidth, obj.StageHeight, 0, 0 ,10 ); causes all the sprites I try to place, to be offset by 5 pixels on both x and y axis.
Note that in my test runs, the resolution used was the same for glViewport, glOrtho and the OpenGL window itself. Allways 800,600. Yet the weird offset seems to be there all the time, enless I enter the offset as shown in the function above.
that code means that the display itself is offset 5 pixels to the right and 5 pixels to the top, compared to the window itself, yet everything displays correctly now.
Any idea why this happens?
The thing thats been keeping me busy all day is the way to properly map the screen x,y coordinates to the sprites displayed onscreen.
Everytime I thought I got it right, the whole viewport seemed to be offset by 5-10 pixels in some direction, making the positioning of sprites a pain in the ass.
I just figured out that passing that offset to the glOrtho command 'fixes' the problem.
Function ehResizeWindow( obj:Stage ) If( obj.Height = 0 ) Then obj.Height = 1; glViewport(0, 0, obj.Width, obj.Height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( 5, obj.StageWidth + 5, obj.StageHeight - 5, -5, 0 ,10 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); End Function
just using: glOrtho( 0, obj.StageWidth, obj.StageHeight, 0, 0 ,10 ); causes all the sprites I try to place, to be offset by 5 pixels on both x and y axis.
Note that in my test runs, the resolution used was the same for glViewport, glOrtho and the OpenGL window itself. Allways 800,600. Yet the weird offset seems to be there all the time, enless I enter the offset as shown in the function above.
that code means that the display itself is offset 5 pixels to the right and 5 pixels to the top, compared to the window itself, yet everything displays correctly now.
Any idea why this happens?