mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 00:58:05 +02:00
Improve this demo in a few ways.
1. Use more reasonable hither/yon clip planes to make better use of shallow (16-bit) z buffers. 2. Use different colors on cube faces to help detect Z fighting if it occurs. 3. Report GL_DEPTH_BITS on start-up.
This commit is contained in:
parent
ee7fece054
commit
34f6243bef
1 changed files with 22 additions and 12 deletions
|
|
@ -71,12 +71,12 @@ typedef Vertex Quad[4];
|
|||
|
||||
/* data to define the six faces of a unit cube */
|
||||
Quad quads[MAXQUAD] = {
|
||||
{ {0,0,0}, {1,0,0}, {1,1,0}, {0,1,0} },
|
||||
{ {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1} },
|
||||
{ {0,0,0}, {1,0,0}, {1,0,1}, {0,0,1} },
|
||||
{ {0,1,0}, {1,1,0}, {1,1,1}, {0,1,1} },
|
||||
{ {0,0,0}, {0,0,1}, {0,1,1}, {0,1,0} },
|
||||
{ {1,0,0}, {1,0,1}, {1,1,1}, {1,1,0} }
|
||||
{ {0,0,0}, {0,0,1}, {0,1,1}, {0,1,0} }, /* x = 0 */
|
||||
{ {0,0,0}, {1,0,0}, {1,0,1}, {0,0,1} }, /* y = 0 */
|
||||
{ {0,0,0}, {1,0,0}, {1,1,0}, {0,1,0} }, /* z = 0 */
|
||||
{ {1,0,0}, {1,0,1}, {1,1,1}, {1,1,0} }, /* x = 1 */
|
||||
{ {0,1,0}, {1,1,0}, {1,1,1}, {0,1,1} }, /* y = 1 */
|
||||
{ {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1} } /* z = 1 */
|
||||
};
|
||||
|
||||
#define WIREFRAME 0
|
||||
|
|
@ -86,7 +86,7 @@ static void error(const char* prog, const char* msg);
|
|||
static void cubes(int mx, int my, int mode);
|
||||
static void fill(Quad quad);
|
||||
static void outline(Quad quad);
|
||||
static void draw_hidden(Quad quad, int mode);
|
||||
static void draw_hidden(Quad quad, int mode, int face);
|
||||
static void process_input(Display *dpy, Window win);
|
||||
static int query_extension(char* extName);
|
||||
|
||||
|
|
@ -101,6 +101,7 @@ int main(int argc, char** argv) {
|
|||
XSetWindowAttributes swa;
|
||||
Window win;
|
||||
GLXContext cx;
|
||||
GLint z;
|
||||
|
||||
dpy = XOpenDisplay(0);
|
||||
if (!dpy) error(argv[0], "can't open display");
|
||||
|
|
@ -134,13 +135,16 @@ int main(int argc, char** argv) {
|
|||
|
||||
/* set up viewing parameters */
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
gluPerspective(20, 1, 0.1, 20);
|
||||
gluPerspective(20, 1, 10, 20);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glTranslatef(0, 0, -15);
|
||||
|
||||
/* set other relevant state information */
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glGetIntegerv(GL_DEPTH_BITS, &z);
|
||||
printf("GL_DEPTH_BITS = %d\n", z);
|
||||
|
||||
#ifdef GL_EXT_polygon_offset
|
||||
printf("using 1.0 offset extension\n");
|
||||
glPolygonOffsetEXT( 1.0, 0.00001 );
|
||||
|
|
@ -160,6 +164,7 @@ int main(int argc, char** argv) {
|
|||
|
||||
static void
|
||||
draw_scene(int mx, int my) {
|
||||
glClearColor(0.25, 0.25, 0.25, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
|
|
@ -206,7 +211,7 @@ cubes(int mx, int my, int mode) {
|
|||
glTranslatef(x, y, z);
|
||||
glScalef(0.8, 0.8, 0.8);
|
||||
for (i = 0; i < MAXQUAD; i++)
|
||||
draw_hidden(quads[i], mode);
|
||||
draw_hidden(quads[i], mode, i);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
|
@ -236,13 +241,18 @@ outline(Quad quad) {
|
|||
}
|
||||
|
||||
static void
|
||||
draw_hidden(Quad quad, int mode) {
|
||||
draw_hidden(Quad quad, int mode, int face) {
|
||||
static const GLfloat colors[3][3] = {
|
||||
{0.5, 0.5, 0.0},
|
||||
{0.8, 0.5, 0.0},
|
||||
{0.0, 0.5, 0.8}
|
||||
};
|
||||
if (mode == HIDDEN_LINE) {
|
||||
glColor3f(0, 0, 0);
|
||||
glColor3fv(colors[face % 3]);
|
||||
fill(quad);
|
||||
}
|
||||
|
||||
/* draw the outline using white, optionally fill the interior with black */
|
||||
/* draw the outline using white */
|
||||
glColor3f(1, 1, 1);
|
||||
outline(quad);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue