I draw a 3d scene which the user can explore using the arrows .
When the ‘1’ key (or any other key different of the arrows) I get the depth buffer values using the glReadPixels function - and save them into a file.
The problem is that I can not see nothing afterwards - the window gets black…
Here is some code (from render scene) .It appears immediatly after flushing the scene buffer :
/* When pressing ‘1’ --> flag – TRUE /
if (flag == TRUE)
{
memset(pixels,0,widthheight);
glDepthRange(100,4000);
glReadPixels(0,0,width,height,GL_DEPTH_COMPONENT,GL_FLOAT,pixels);
maxFloat = 0;
minFloat = 1;
for (int i=0;i<width*height;++i)
{
maxFloat = max(maxFloat,pixels[i]);
minFloat = min(minFloat,pixels[i]);
}
range = maxFloat - minFloat;
if (range == 0)
scale = 0;
else
scale = 1.0f/range;
/* Reseting the flag */
flag = FALSE;
ofstream A;
A.open("data",ios::binary);
A.write(pixels,width*height);
A.close();
}
glFlush();