#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 void init (void) { int i; GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 }; glClearColor (0.0, 0.0, 0.0, 1.0); glColor4fv (white); glDisable (GL_DITHER); } static void test (void) { GLfloat defaultColor[] = { 0.0, 0.0, 0.0, 1.0 }; int i, j; GLfloat buf; GLfloat n, f; GLubyte img[1] = {0xff}; glClearDepth (0); glClearColor (0.0, 0.0, 0.0, 1.0); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable (GL_DEPTH_TEST); glDepthFunc (GL_ALWAYS); glColor3f (0.0, 0.0, 0.0); n = 0.0; f = 1.0; glDepthRange(n, f); GLfloat nD = 0.25; glRasterPos3f (0.2, 0.2, nD); glBitmap(1, 1, 0, 0, 0, 0, img); //glDrawPixels(1, 1, GL_RGB, GL_FLOAT, defaultColor); glReadPixels (0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &buf); printf ("read out pixels: (0, 0) = %f, ", buf); printf ("should be %f\n", (f-n)/2*nD+(f+n)/2); } void display (void) { glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho (0, WINDSIZEX, 0, WINDSIZEY, 1.0, -1.0); test (); } int main (int argc, char **argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize (WINDSIZEX, WINDSIZEY); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init (); glutDisplayFunc (display); glutMainLoop (); return 0; }