I have a problem.I want to change mouse coordinate to gl coordinate using below function.But it doesn’t work.
What’s going wrong??
And Is there any better way to do this?
Here is the code:
GLdouble modelMatrix[16];
GLdouble projMatrix[16];
GLint viewport[4];
glGetDoublev(GL_MODELVIEW_MATRIX ,modelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX ,projMatrix);
glGetIntegerv(GL_VIEWPORT,viewport);
GLdouble winX,winY;
winX = mousePoint.x;
winY = viewport[3] - MousePoint.y;
GLfloat winZ ;
glReadPixels(winX,winY,1,1,GL_DEPTH_COMPONENT ,GL_FLOAT, &winZ);
GLdouble glX,glY,glZ;
int value =gluUnProject(winX,winY,winZ,modelMatrix,projMatrix,viewport,
&glX,&glY,&glZ); //sometimes value is false,why?