in openinventor ,i use the callback node to read the z-buffer value and want to get the z coordinate in the real world. I use the glReadPixels() to read the z-buffer, but all the depth
value i reading is 1. I do not know why i can not get it. my programme
is following.
//project the elbowCenter to the screen
elbowCenter.setValue(1.0,-3.0,0.0);
SbViewVolume myViewVolume=myCamera->getViewVolume();
SbVec3f pointScreen;
int x,y;
myViewVolume. projectToScreen(SbVec3f(elbowCenter[0], elbowCenter[1],
elbowCenter[2]),pointScreen);
x=pointScreen[0]*size[0];
y=pointScreen[1]*size[1];
glEnable (GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
//get the real world coordinate --posz
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );
winX = x;
winY = y;
glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ
);
gluUnProject( winX, winY, winZ, modelview, projection, viewport,
&posX, &posY, &posZ);