demos: add missing binaries to .gitignore
[mesa-demos.git] / src / tests / backspecular.c
blob962071f4b5e845807d0705ec88cc2abeb8ed68cb
1 #include <stdlib.h>
2 #include <GL/glew.h>
3 #include "glut_wrap.h"
6 static const float black[4] = { 0, 0, 0, 1 };
7 static const float white[4] = { 1, 1, 1, 1 };
8 static const float diffuse[4] = { 1, 0, 0, 1 };
9 static const float diffuseb[4] = { 0, 1, 0, 1 };
10 static const float specular[4] = { 0.5, 0.5, 0.5, 1 };
11 static const float ambient[4] = { 0.2, 0.2, 0.2, 1 };
12 static const float lightpos[4] = { 0, 0, 10, 0 };
13 static const float shininess = 50;
15 static double angle = 0.0;
17 static int autorotate = 1;
18 static double angle_delta = 1.0;
19 static int timeout = 10;
22 static void
23 display(void)
25 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
26 glPushMatrix();
27 glRotated(angle, 0.0, 1.0, 0.0);
29 glBegin(GL_QUADS);
30 glColor3f(1, 1, 1);
31 glNormal3d(0, 0, 1);
32 glVertex3d(-1, -1, 0);
33 glVertex3d(+1, -1, 0);
34 glVertex3d(+1, +1, 0);
35 glVertex3d(-1, +1, 0);
36 glEnd();
38 glPopMatrix();
40 glutSwapBuffers();
44 static void
45 timer(int value)
47 angle += angle_delta;
48 glutTimerFunc(timeout, timer, 0);
49 glutPostRedisplay();
53 static void
54 key(unsigned char key, int x, int y)
56 if (key == 27) {
57 exit(0);
62 int
63 main(int argc, char **argv)
65 /* init glut */
66 glutInit(&argc, argv);
67 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
68 glutCreateWindow("Backface specular test");
69 glutDisplayFunc(display);
70 glutKeyboardFunc(key);
71 if (autorotate)
72 glutTimerFunc(timeout, timer, 0);
74 /* setup lighting */
75 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
76 glMaterialfv(GL_BACK, GL_DIFFUSE, diffuseb);
78 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
79 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
80 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
81 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shininess);
83 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
84 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
85 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
87 glLightfv(GL_LIGHT0, GL_AMBIENT, black);
88 glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
89 glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
90 glLightfv(GL_LIGHT0, GL_SPECULAR, white);
92 glDisable(GL_CULL_FACE);
93 glEnable(GL_LIGHTING);
94 glEnable(GL_LIGHT0);
96 /* setup camera */
97 glMatrixMode(GL_PROJECTION);
98 gluPerspective(30.0, 1.0, 1.0, 10.0);
99 glMatrixMode(GL_MODELVIEW);
100 gluLookAt(0.0, 0.0, 5.0,
101 0.0, 0.0, 0.0,
102 0.0, 1.0, 0.0);
104 /* setup misc */
105 glEnable(GL_DEPTH_TEST);
106 glClearColor(0, 0, 1, 1);
108 /* run */
109 glutMainLoop();
111 return 0;