get depth by glReadPixels()?

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(GLfloat));///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| |wzz<0.0)
		continue; //error!
              count++;
      }

Any problems in it?

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).

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.

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.

what’s “hw acc”?

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

hw acc == short_of(hardware acceleration)

How to check if I’m using the hardware acceleration.

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