2 * Test glRead/DrawPixels for GL_DEPTH_COMPONENT, with pixelzoom.
11 #define GL_GLEXT_PROTOTYPES
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, 0);
25 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
28 glViewport(0, 0, 100, 100);
29 glMatrixMode(GL_PROJECTION
);
31 glOrtho(-1, 1, -1, 1, -1, 0); /* clip away back half of sphere */
32 glMatrixMode(GL_MODELVIEW
);
34 glutSolidSphere(1.0, 20, 10);
36 /* read the depth image */
37 glReadPixels(0, 0, 100, 100, GL_DEPTH_COMPONENT
, GL_FLOAT
, depth
);
39 for (i
= 1; i
< 100 * 100; i
++) {
45 printf("Depth value range: [%f, %f]\n", min
, max
);
47 /* draw depth image with scaling (into z buffer) */
48 glPixelZoom(4.0, 4.0);
49 glWindowPos2i(100, 0);
50 glDrawPixels(100, 100, GL_DEPTH_COMPONENT
, GL_FLOAT
, depth
);
52 /* read back scaled depth image */
53 glReadPixels(100, 0, 400, 400, GL_DEPTH_COMPONENT
, GL_FLOAT
, depth2
);
54 /* draw as luminance */
55 glPixelZoom(1.0, 1.0);
56 glDrawPixels(400, 400, GL_LUMINANCE
, GL_FLOAT
, depth2
);
62 static void Reshape(int width
, int height
)
66 glViewport(0, 0, width
, height
);
70 static void Key(unsigned char key
, int x
, int y
)
83 static void Init(void)
85 const GLfloat blue
[4] = {.1, .1, 1.0, 0.0};
86 const GLfloat gray
[4] = {0.2, 0.2, 0.2, 1.0};
87 const GLfloat white
[4] = {1.0, 1.0, 1.0, 1.0};
88 const GLfloat pos
[4] = {0, 0, 10, 0};
90 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
91 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
93 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, blue
);
94 glLightfv(GL_LIGHT0
, GL_AMBIENT
, gray
);
95 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, white
);
96 glLightfv(GL_LIGHT0
, GL_POSITION
, pos
);
97 glEnable(GL_LIGHTING
);
99 glEnable(GL_DEPTH_TEST
);
103 int main(int argc
, char *argv
[])
105 glutInit(&argc
, argv
);
106 glutInitWindowPosition(0, 0);
107 glutInitWindowSize(WinWidth
, WinHeight
);
108 glutInitDisplayMode(GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
109 glutCreateWindow(argv
[0]);
110 glutReshapeFunc(Reshape
);
111 glutKeyboardFunc(Key
);
112 glutDisplayFunc(Display
);