2 * Test glRead/DrawPixels for GL_DEPTH_COMPONENT, with pixelzoom.
14 static GLint WinWidth
= 500, WinHeight
= 500;
17 static void Display(void)
19 GLfloat depth
[100 * 100];
20 GLfloat depth2
[400 * 400];
24 glClearColor(0.5, 0.5, 0.5, 1.0);
25 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
27 glEnable(GL_DEPTH_TEST
);
30 glViewport(0, 0, 100, 100);
31 glMatrixMode(GL_PROJECTION
);
33 glOrtho(-1, 1, -1, 1, -1, 0); /* clip away back half of sphere */
34 glMatrixMode(GL_MODELVIEW
);
36 glutSolidSphere(1.0, 20, 10);
38 /* read the depth image */
39 glReadPixels(0, 0, 100, 100, GL_DEPTH_COMPONENT
, GL_FLOAT
, depth
);
41 for (i
= 1; i
< 100 * 100; i
++) {
47 printf("Depth value range: [%f, %f]\n", min
, max
);
49 /* draw depth image with scaling (into z buffer) */
50 glPixelZoom(4.0, 4.0);
51 glColor4f(1, 0, 0, 0);
52 glWindowPos2i(100, 0);
53 glDrawPixels(100, 100, GL_DEPTH_COMPONENT
, GL_FLOAT
, depth
);
55 glDisable(GL_DEPTH_TEST
);
57 /* read back scaled depth image */
58 glReadPixels(100, 0, 400, 400, GL_DEPTH_COMPONENT
, GL_FLOAT
, depth2
);
59 /* draw as luminance */
60 glPixelZoom(1.0, 1.0);
61 glDrawPixels(400, 400, GL_LUMINANCE
, GL_FLOAT
, depth2
);
67 static void Reshape(int width
, int height
)
71 glViewport(0, 0, width
, height
);
75 static void Key(unsigned char key
, int x
, int y
)
88 static void Init(void)
90 const GLfloat blue
[4] = {.1, .1, 1.0, 1.0};
91 const GLfloat gray
[4] = {0.2, 0.2, 0.2, 1.0};
92 const GLfloat white
[4] = {1.0, 1.0, 1.0, 1.0};
93 const GLfloat pos
[4] = {0, 0, 10, 0};
95 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
96 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
98 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, blue
);
99 glLightfv(GL_LIGHT0
, GL_AMBIENT
, gray
);
100 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, white
);
101 glLightfv(GL_LIGHT0
, GL_POSITION
, pos
);
102 glEnable(GL_LIGHTING
);
107 int main(int argc
, char *argv
[])
109 glutInit(&argc
, argv
);
110 glutInitWindowPosition(0, 0);
111 glutInitWindowSize(WinWidth
, WinHeight
);
112 glutInitDisplayMode(GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
113 glutCreateWindow(argv
[0]);
115 glutReshapeFunc(Reshape
);
116 glutKeyboardFunc(Key
);
117 glutDisplayFunc(Display
);