PDA

View Full Version : why can't get pixel Z depth with glReadPixels



ljz
05-19-2009, 09:57 AM
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];
glReadPixels(0,0,width,height,GL_DEPTH_COMPONENT,G L_FLOAT,z);

Any comment is welcome and appreciated.

Nighthawk
05-20-2009, 02:11 AM
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

ljz
05-20-2009, 02:37 AM
Reading the RGB values works. But I do not test the others. I can have a try. Thanks.

Dark Photon
05-26-2009, 05:18 AM
glReadPixels(0,0,width,height,GL_DEPTH_COMPONENT,G L_FLOAT,z);
This most definitely works (or has worked) for me on NVidia HW under Linux.

ljz
05-26-2009, 06:54 AM
Yes, it also works for me in UG, another CAD software. But doesn't work in proE.