PDA

View Full Version : glReadPixels(), Depth and gluUnProject()?



Thales
08-01-2002, 06:16 PM
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);
glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
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?

Thales
08-01-2002, 08:14 PM
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);