glReadPixels(), Depth and gluUnProject()?

I’m trying to access the z or depth value at a point clicked by the mouse using glReadPixels(), and am getting a nonsensical value returned.

glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
realy = viewport[3] - (GLint) point.y - 1;
glReadPixels(x, realy, 1, 1, GL_DEPTH_COMPONENT, GL_DOUBLE, &winz);

gluUnProject((GLdouble)point.x, (GLdouble)realy, winz, modelMatrix, 
	projMatrix, viewport, &objx, &objy, &objz);

The value returned for winz is consistently -9.25596e+061. A number which I don’t understand!

This doesn’t make any sense, since there is a polygon object right below the mouse where I click to test for depth.

Anyone know what I might be doing wrong here?

I figured it out.

by setting up the return type as GL_FLOAT rather than GL_DOUBLE the problem was solved.

glReadPixels(x, realy, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winz);