glReadPixels/gluUnProject problem


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):
GLint viewport[4];
GLdouble mvmatrix[16], projmatrix[16];
GLint realY;
realY = viewport[3] - screenY;
GLfloat winZ;
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,

You certainly use something like this for to clear the screen before to draw the object :


So, the value of winZ is always 0.67 except where you have draw your object (where the Z value is set to anothers values)