I am new to OpenGL, and I am having this annoying problem for a while. I hope someone can help me. I am drawing some objects in my scene successfully, and trying to show in status bar of my application the object coord while moving mouse over it.
My code look like this (screenX and screenY are mouse position):
GLdouble mvmatrix, projmatrix;
realY = viewport - screenY;
glReadPixels(screenX, realY, 1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&winZ);
return gluUnProject((GLdouble)screenX,(GLdouble)realY, (GLdouble)winZ, mvmatrix,projmatrix,viewport, &wx,&wy,&wz);
I am using glFrustum with near plane= 15.0 and far=1000.0
This is working perfectly when my mouse is over the object, but once it is over an empty area in the screen, it returns strange values: winZ is always 0.67 and wz,wy, and wz are odd.
Thanks in advance,