How to get depth value form depth buffer in OpenGL

glEnable( GL_DEPTH_TEST );
glDepthMask( 1 );
glDepthFunc( GL_LEQUAL );

float onePixel;
glReadPixels( xPos, yPos, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &onePixel );
float *depth = new float[w*h];
glReadPixels( xPos, yPos, w, h, GL_DEPTH_COMPONENT, GL_FLOAT, depth );
delete[] depth;

Tags:,

Add a Comment