PDA

View Full Version : get depth by glReadPixels()?



newname
09-10-2002, 06:04 PM
Hi, I cann't get depth buffer correctly. The result was always something like: -4294967296.00.

I use the codes like:

GLfloat * depthResults = new GLfloat[winWidth * winHeight];
memset(depthResults,0,winWidth*winHeight*sizeof(GL float));///added 020907
glReadPixels(0, 0, winWidth, winHeight, GL_DEPTH_COMPONENT, GL_FLOAT, depthResults);

long count=0;
for(int y = 0; y < winHeight; y++)
for(int x = 0; x < winWidth; x++)
{
GLfloat wzz=depthResults[winWidth * y + x];
if(wzz>1.0&#0124; &#0124;wzz<0.0)
continue; //error!
count++;
}

Any problems in it?

dawn
09-10-2002, 11:53 PM
Check for the exact window dimensions, because if winHeight or winWidth are larger than the real size of the gl window, the result of ReadPixels will be undefined (and that value of yours seems like that).

newname
09-11-2002, 03:51 AM
I tried to use a small window, but the results were the same.

if I added two lines:
glPixelTransferf(GL_DEPTH_SCALE, 0.8f);
glPixelTransferf(GL_DEPTH_BIAS, 0.1f);

the results were always 0.00.

dawn
09-11-2002, 04:18 AM
try to read only one component:

float value;
glReadPixels(10, 10, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &value);

and also check if you are running using hw acc.

newname
09-11-2002, 05:21 AM
what's "hw acc"?

When I run it in Win98, it sometimes seems correct. But in Win2k, it never succeeded.

davepermen
09-11-2002, 05:24 AM
hw acc == short_of(hardware acceleration)

newname
09-11-2002, 11:26 PM
How to check if I'm using the hardware acceleration.


Originally posted by davepermen:
hw acc == short_of(hardware acceleration)