Sign in to follow this  
gpr1me

Screen X Y Position change.

Recommended Posts

gpr1me    122
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?

Share this post


Link to post
Share on other sites
atultuff    152
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 ..

Share this post


Link to post
Share on other sites
Winterhell    115
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.

Share this post


Link to post
Share on other sites
yadango    567
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.

Share this post


Link to post
Share on other sites
snard6    152
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.

Share this post


Link to post
Share on other sites
raptorstrike    181
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this