No, I’m certain that’s not it. There’s no projection matrix involved.
I’m setting these values using glClearDepth/glClear, then reading them back using both glReadPixels( GL_UNSIGNED_INT_24_8 ) and ( GL_FLOAT ), and comparing the results.
Here’s a short GLUT test program that illustrates the problem:
<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define GL_GLEXT_PROTOTYPES 1
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
const int RES = 512;
//-----------------------------------------------------------------------
void checkGLErrors( const char *s )
{
while ( 1 )
{
int x = glGetError() ;
if ( x == GL_NO_ERROR )
return;
fprintf( stderr, "%s: OpenGL error: %s
",
s ? s : "", gluErrorString ( x ) ) ;
}
}
//-----------------------------------------------------------------------
void doTest()
{
//-----------------------------------------------------
// Clear depth texture and check values
//-----------------------------------------------------
// Create depth texture (24-bit fixed)
GLuint depth_tex;
glGenTextures ( 1, &depth_tex );
glBindTexture ( GL_TEXTURE_2D, depth_tex );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE );
glTexImage2D ( GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, RES, RES, 0,
GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0 );
// Create/bind FBO to write depth texture
GLuint depth_fbo;
glGenFramebuffers( 1, &depth_fbo );
glBindFramebuffer( GL_FRAMEBUFFER, depth_fbo );
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_TEXTURE_2D, depth_tex, 0 );
// Clear to next-to-last depth step
// NOTE: 0xffffff = 2^24-1.
//glClearDepth( float( 0xffffff ) / float( 0xffffff ) );
glClearDepth( float( 0xfffffe ) / float( 0xffffff ) );
//glClearDepth( float( 0xfffffd ) / float( 0xffffff ) );
glClear( GL_DEPTH_BUFFER_BIT );
// See what "integer" depth value is in the framebuffer
// NOTE: It should be 0xfffffe.
// AND : It is (on NVidia 260.19.44).
GLuint pval;
glPixelStorei( GL_PACK_ALIGNMENT, 1 );
glReadPixels( 0, 0, 1, 1, GL_DEPTH_STENCIL,
GL_UNSIGNED_INT_24_8, &pval );
printf( "ReadPixels DEPTH uint = 0x%.6x
", pval >> 8 );
// NOW see what 0..1 "normalized" depth value the driver says is there.
// NOTE: Should be (2^24-2)/(2^24-1) = 0xfffffe/0xffffff = 0.999999940395
// BUT!: It's 1.000000000000 (on NVidia 260.19.44)
float fval;
glReadPixels ( 0, 0, 1, 1, GL_DEPTH_COMPONENT,
GL_FLOAT, &fval );
printf( "ReadPixels DEPTH float = %.12f
", fval );
checkGLErrors( "doTest - END" );
}
//-----------------------------------------------------------------------
int main ( int argc, char **argv )
{
// Init GL context
glutInit ( &argc, argv ) ;
glutInitDisplayMode ( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ) ;
glutInitWindowSize ( 500, 500 ) ;
glutCreateWindow ( "GL Test" ) ;
doTest();
//glutMainLoop () ;
return 0 ;
}
[/QUOTE]</div>