PDA

View Full Version : opengl coordinate system



Registrar
02-10-2011, 08:26 PM
I find the OpenGL Co-ordinate system really hard to use. I would much rather have things like glVertex2f(-100,-100) put a vertex back 100 pixels in the X and Y direction from the origin, instead of it being totally off the screen. Is there any way that I can do this? I was thinking mabey just glTranslate'ing out in the Z direction but I am not sure if this will work.

ZbuffeR
02-10-2011, 11:52 PM
If you want to use pixel coordinates, use the correct projection, like for example :
glMatrixMode(GL_PROJECTION);
glLoadIdentity ();
glOrtho(0, WindowWidthInPixels, 0, WindowHeightInPixels, -1, 1);

Registrar
02-10-2011, 11:57 PM
Thanks for your answer.
When I use that method, the origin (0,0) seems to be at the bottom left corner of the screen. Is there anyway to make it the top right? I don't really understand the left, right, top, bottom paramaters.

mobeen
02-10-2011, 11:58 PM
With GL u decide what to do. As pointed out by ZBuffer set the appropriate projection matrix and u will have what u want.

ZbuffeR
02-11-2011, 02:23 AM
Top right ? This is unusual.
left, right, top, bottom paramaters define the range of GL coordinates visible on the glViewPort. So reverse order to reverse axes, like :
glOrtho(width,0,height,0,-1,1);