why can't get pixel Z depth with glReadPixels

I am using pro/Toolkit to develope some code to read pixel depth of proE model from proE view window with openGL function glReadPixels(), but all I got was 1. Actually it should be different value for different pixel of the displaying model. The codes are as following,

const int width=1024;
const int height=768;
float z[width*height];

Any comment is welcome and appreciated.

Just some random ideas:

  • Does glClear(GL_DEPTH_BUFFER_BIT) before readback change the result?
  • Does reading the RGBA values work?
  • set glReadBuffer(GL_BACK);
  • set via glPixelTransferf: GL_DEPTH_SCALE=1.0f/GL_DEPTH_BIAS=0.0f

Reading the RGB values works. But I do not test the others. I can have a try. Thanks.

This most definitely works (or has worked) for me on NVidia HW under Linux.

Yes, it also works for me in UG, another CAD software. But doesn’t work in proE.