2 * Test glDrawPixels(GL_DEPTH_COMPONENT)
4 * We load a window-sized buffer of Z values so that Z=1 at the top and
5 * Z=0 at the bottom (and interpolate between).
6 * We draw that image into the Z buffer, then draw an ordinary cube.
7 * The bottom part of the cube should be "clipped" where the cube fails
10 * Press 'd' to view the Z buffer as a grayscale image.
17 #include "glut_wrap.h"
18 #include "../util/showbuffer.c"
22 static GLfloat Xrot
= 50, Yrot
= 40, Zpos
= 6;
23 static GLboolean Anim
= GL_FALSE
;
25 static int Width
= 200, Height
= 200;
27 static GLboolean showZ
= 0;
42 glClearColor(0, 0, 0.5, 0);
43 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
49 glDrawPixels(Width
, Height
, GL_DEPTH_COMPONENT
, GL_FLOAT
, z
);
52 glTranslatef(-0.75, 0, Zpos
);
53 glutSolidSphere(1.0, 20, 10);
60 glTranslatef(0, 0, Zpos
);
61 glRotatef(Xrot
, 1, 0, 0);
62 glRotatef(Yrot
, 0, 1, 0);
67 /* drawpixels after cube */
70 //glColorMask(0,0,0,0);
71 glDrawPixels(Width
, Height
, GL_DEPTH_COMPONENT
, GL_FLOAT
, z
);
75 ShowDepthBuffer(Width
, Height
, 0.0, 1.0);
83 Reshape(int width
, int height
)
85 glViewport(0, 0, width
, height
);
86 glMatrixMode(GL_PROJECTION
);
88 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 30.0);
89 glMatrixMode(GL_MODELVIEW
);
91 glTranslatef(0.0, 0.0, -15.0);
96 z
= (float *) malloc(width
* height
* 4);
99 for (i
= 0; i
< height
; i
++) {
100 float zval
= (float) i
/ (height
- 1);
101 for (j
= 0; j
< width
; j
++) {
110 Key(unsigned char key
, int x
, int y
)
112 const GLfloat step
= 1.0;
133 glutDestroyWindow(Win
);
142 SpecialKey(int key
, int x
, int y
)
144 const GLfloat step
= 3.0;
168 /* setup lighting, etc */
169 glEnable(GL_DEPTH_TEST
);
170 glEnable(GL_LIGHTING
);
176 main(int argc
, char *argv
[])
178 glutInit(&argc
, argv
);
179 glutInitWindowPosition(0, 0);
180 glutInitWindowSize(400, 400);
181 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
182 Win
= glutCreateWindow(argv
[0]);
184 glutReshapeFunc(Reshape
);
185 glutKeyboardFunc(Key
);
186 glutSpecialFunc(SpecialKey
);
187 glutDisplayFunc(Draw
);