The following code was used to readthe color and depth of apixel in Pro/E model window by using openGL functions to perfom some simulation. All the other opengl functions worked properly except depth reading. I don't know why. Anybody help me. Thanks a lot.
Now given a model displayed in Pro/E, as shown in this fig. when I tried to run the code, the resultsare shownin the comments.
View attachment 4895
intwinWidth, winHeight;
GLint iViewParams[4];
glGetIntegerv(GL_VIEWPORT, iViewParams);//It works
winWidth= iViewParams[2]-iViewParams[0];
winHeight= iViewParams[3]-iViewParams[1];
BYTEbtRGB[3];
GLfloatfZBuffer[1];
//Lower-left corner
glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, btRGB);//It works
glReadPixels(0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, fZBuffer); //dosn't work properly
//The center of the view
int cw = winWidth/2;
int ch = winHeight/2;
glReadPixels(cw, ch, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, fZBuffer);//dosn't work, always get fZBuffer[0]=1.0 everywhere
Actually the depth of every pixel of the model surface should be different value, but here it kept 1.0 for all pixels. This problem have troubled me for quite a long time. I really appreciate any kind of your help.
Now given a model displayed in Pro/E, as shown in this fig. when I tried to run the code, the resultsare shownin the comments.
View attachment 4895
intwinWidth, winHeight;
GLint iViewParams[4];
glGetIntegerv(GL_VIEWPORT, iViewParams);//It works
winWidth= iViewParams[2]-iViewParams[0];
winHeight= iViewParams[3]-iViewParams[1];
BYTEbtRGB[3];
GLfloatfZBuffer[1];
//Lower-left corner
glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, btRGB);//It works
glReadPixels(0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, fZBuffer); //dosn't work properly
//The center of the view
int cw = winWidth/2;
int ch = winHeight/2;
glReadPixels(cw, ch, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, fZBuffer);//dosn't work, always get fZBuffer[0]=1.0 everywhere
Actually the depth of every pixel of the model surface should be different value, but here it kept 1.0 for all pixels. This problem have troubled me for quite a long time. I really appreciate any kind of your help.