# OpenGL problem converting windows coordinates to object coordinates

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

## 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 on other sites
Well from your example you aren't sending x = 0 y = 240 its backwards...
You are sending x = 240 and y = 0...

##### Share on other sites
>> 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 on other sites
e-0.12 is a very small number eg 0.00000000000012
print out winZ as well does it look right?

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633661
• Total Posts
3013221
×