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=240,y=0
glX = -4.342…e-0.12
glY = 2.17…e-011