Screen X Y Position change.

Started by
5 comments, last by rpg_code_master 18 years ago
I want to be able to change the way OpenGL reads my screen coordinates. What i mean by this is: OpenGL reads the TOP LEFT of the opengl screen as X=0 and Y=0. Instead of that i would like it to read the MIDDLE MIDDLE as X=0 and Y=0. Basically i want it to be a cartesian coordinate system. If there a function for doing this or do i have to perform the calculation myself?
Advertisement
Hey!

I am not a OpenGl programmer , but you basically need to shift your origin to the middle of the screen. In Windows SDK we have a function
SetViewportOrgEx(..) to set the origin of the viewport ,

Hope this helps in some way ..
when rendering(using NeHe tutorials and others) (0,0,0) is the center of the screen.(-1,-1,z) is the left bottom and (1,1,z) is the top right.if you mean in way of "rendering different views" like split-screen(used in some games for multy)
you can consider another tut again on NeHe,for viewports.
Quote:Original post by gpr1me
OpenGL reads the TOP LEFT of the opengl screen as X=0 and Y=0. Instead of that i would like it to read the MIDDLE MIDDLE as X=0 and Y=0. Basically i want it to be a cartesian coordinate system. If there a function for doing this or do i have to perform the calculation myself?


Isn't the bottom-left (0,0)? Last I recall using glWindowPos(0,0) it put text at the bottom-left of the window ;). As said above I'd do the calculation myself as when you have multiple viewports window coordinates go out the window anyways. So either way you're going to be stuck with mapping coordinates.
I've never done OpenGL, so i'm not an expert at this, but you could just do it the lazy man's way. That is to write a function, that does a little shift operation, and then calls the OpenGL function. Then just use that function each time instead of the OpenGL one.
yeah unless you mess with the veiwport 0,0 is the direct center of the screen. (-1,1) being top left, (1,1) being top right, (1,-1) being bottom right, (-1,-1) being bottom left

also, whenever you call glPushMatrix(); it makes the new camera position the new center of the screen regardless of transitions and rotations. The matrix is reverted back to the true world origon when glPopMatrix(); is called
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Quote:Original post by gpr1me
I want to be able to change the way OpenGL reads my screen coordinates. What i mean by this is:

OpenGL reads the TOP LEFT of the opengl screen as X=0 and Y=0. Instead of that i would like it to read the MIDDLE MIDDLE as X=0 and Y=0. Basically i want it to be a cartesian coordinate system. If there a function for doing this or do i have to perform the calculation myself?

I gather that you are in Ortho mode. The easiest method of doing this is as snard6 said. Just create a function like so: -

void MyGlVertex2f( float fx, float fy, int nScreenW, int nScreenH ){    // shift in order to get the coord    glVertex3f( fx + (nScreenW >> 1), fy + (nScreenH  >> 1));} // end MyGlVertex2f


Beware though that this method will not work for display lists and index arrays

This topic is closed to new replies.

Advertisement