2 * Test glRead/DrawPixels for GL_DEPTH_COMPONENT, with pixelzoom.
14 static GLint WinWidth
= 500, WinHeight
= 500;
15 static GLboolean Invert
= GL_FALSE
;
16 static GLboolean TestPacking
= GL_FALSE
;
17 static GLboolean TestList
= GL_FALSE
;
20 static void Display(void)
22 GLfloat depth
[100 * 100 * 2];
23 GLfloat depth2
[400 * 400]; /* *2 to test pixelstore stuff */
25 GLenum depthType
= GL_FLOAT
;
27 glClearColor(0.5, 0.5, 0.5, 1.0);
28 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
30 glEnable(GL_DEPTH_TEST
);
33 glViewport(0, 0, 100, 100);
34 glMatrixMode(GL_PROJECTION
);
36 glOrtho(-1, 1, -1, 1, -1, 0); /* clip away back half of sphere */
37 glMatrixMode(GL_MODELVIEW
);
39 glutSolidSphere(1.0, 20, 10);
42 glPixelStorei(GL_PACK_ROW_LENGTH
, 120);
43 glPixelStorei(GL_PACK_SKIP_PIXELS
, 5);
46 /* read the depth image */
47 glReadPixels(0, 0, 100, 100, GL_DEPTH_COMPONENT
, depthType
, depth
);
48 if (depthType
== GL_FLOAT
) {
52 for (i
= 1; i
< 100 * 100; i
++) {
58 printf("Depth value range: [%f, %f]\n", min
, max
);
62 glPixelStorei(GL_PACK_ROW_LENGTH
, 0);
63 glPixelStorei(GL_PACK_SKIP_PIXELS
, 0);
64 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 120);
65 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 5);
68 /* draw depth image with scaling (into z buffer) */
69 glPixelZoom(4.0, 4.0);
70 glColor4f(1, 0, 0, 0);
71 glWindowPos2i(100, 0);
73 glPixelTransferf(GL_DEPTH_SCALE
, -1.0);
74 glPixelTransferf(GL_DEPTH_BIAS
, 1.0);
78 glNewList(list
, GL_COMPILE
);
79 glDrawPixels(100, 100, GL_DEPTH_COMPONENT
, depthType
, depth
);
82 glDeleteLists(list
, 1);
85 glDrawPixels(100, 100, GL_DEPTH_COMPONENT
, depthType
, depth
);
88 glPixelTransferf(GL_DEPTH_SCALE
, 1.0);
89 glPixelTransferf(GL_DEPTH_BIAS
, 0.0);
93 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
94 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
97 glDisable(GL_DEPTH_TEST
);
99 /* read back scaled depth image */
100 glReadPixels(100, 0, 400, 400, GL_DEPTH_COMPONENT
, GL_FLOAT
, depth2
);
101 /* draw as luminance */
102 glPixelZoom(1.0, 1.0);
103 glDrawPixels(400, 400, GL_LUMINANCE
, GL_FLOAT
, depth2
);
109 static void Reshape(int width
, int height
)
113 glViewport(0, 0, width
, height
);
117 static void Key(unsigned char key
, int x
, int y
)
126 TestPacking
= !TestPacking
;
127 printf("Test pixel pack/unpack: %d\n", TestPacking
);
130 TestList
= !TestList
;
131 printf("Test dlist: %d\n", TestList
);
141 static void Init(void)
143 const GLfloat blue
[4] = {.1, .1, 1.0, 1.0};
144 const GLfloat gray
[4] = {0.2, 0.2, 0.2, 1.0};
145 const GLfloat white
[4] = {1.0, 1.0, 1.0, 1.0};
146 const GLfloat pos
[4] = {0, 0, 10, 0};
148 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
149 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
151 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, blue
);
152 glLightfv(GL_LIGHT0
, GL_AMBIENT
, gray
);
153 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, white
);
154 glLightfv(GL_LIGHT0
, GL_POSITION
, pos
);
155 glEnable(GL_LIGHTING
);
160 int main(int argc
, char *argv
[])
162 glutInit(&argc
, argv
);
163 glutInitWindowPosition(0, 0);
164 glutInitWindowSize(WinWidth
, WinHeight
);
165 glutInitDisplayMode(GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
166 glutCreateWindow(argv
[0]);
168 glutReshapeFunc(Reshape
);
169 glutKeyboardFunc(Key
);
170 glutDisplayFunc(Display
);