Jump to content
  • Advertisement
Sign in to follow this  
nextengine

OpenGL problem converting windows coordinates to object coordinates

This topic is 4396 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am trying to convert windows coordinates to object ( gl ) coordinates, i am having random values as a result. Also, opengl cooordinates start from leftbottom corner of window, but my origin is at the middle of the window, and objects are drawn in respect to origin. i am confused, somebody clarify. following is the code..getting weird values. void getOGLPos(int x, int y, GLdouble* glX, GLdouble* glY, GLdouble* glZ ) { GLint viewport[4]; GLdouble modelview[16]; GLdouble projection[16]; GLfloat winX, winY, winZ; glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); glGetDoublev( GL_PROJECTION_MATRIX, projection ); glGetIntegerv( GL_VIEWPORT, viewport ); winX = (float)x; winY = (float)viewport[3] - (float)y; glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); gluUnProject( winX, winY, winZ, modelview, projection, viewport, glX, glY, glZ); } //Calls GLdouble glX=0.0,glY=0.0,glZ=0.0; getOGLPos( 240,0,&glX,&glY,&glZ); Values I am getting, for Windows values x=0, y = 240. Point should be close to left bottom, as my width and height of window are 600. glX = -4.342......e-0.12 glY = 2.17.................e-011

Share this post


Link to post
Share on other sites
Advertisement
>> values x=0, y = 240. Point should be close to left bottom, as my width and height of window are 600.

I meant to say x=240 y=0. sorry

Share this post


Link to post
Share on other sites
e-0.12 is a very small number eg 0.00000000000012
so perhaps the answers correct
print out winZ as well does it look right?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!