132001f49Smrg#include <stdlib.h>
232001f49Smrg#include <GL/glew.h>
332001f49Smrg#include "glut_wrap.h"
432001f49Smrg
532001f49Smrg
632001f49Smrgstatic const float black[4]    = { 0, 0, 0, 1 };
732001f49Smrgstatic const float white[4]    = { 1, 1, 1, 1 };
832001f49Smrgstatic const float diffuse[4]  = { 1, 0, 0, 1 };
932001f49Smrgstatic const float diffuseb[4] = { 0, 1, 0, 1 };
1032001f49Smrgstatic const float specular[4] = { 0.5, 0.5, 0.5, 1 };
1132001f49Smrgstatic const float ambient[4]  = { 0.2, 0.2, 0.2, 1 };
1232001f49Smrgstatic const float lightpos[4] = { 0, 0, 10, 0 };
1332001f49Smrgstatic const float shininess = 50;
1432001f49Smrg
1532001f49Smrgstatic double angle = 0.0;
1632001f49Smrg
1732001f49Smrgstatic int autorotate = 1;
1832001f49Smrgstatic double angle_delta = 1.0;
1932001f49Smrgstatic int timeout = 10;
2032001f49Smrg
2132001f49Smrg
2232001f49Smrgstatic void
2332001f49Smrgdisplay(void)
2432001f49Smrg{
2532001f49Smrg   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2632001f49Smrg   glPushMatrix();
2732001f49Smrg   glRotated(angle, 0.0, 1.0, 0.0);
2832001f49Smrg
2932001f49Smrg   glBegin(GL_QUADS);
3032001f49Smrg   glColor3f(1, 1, 1);
3132001f49Smrg   glNormal3d(0, 0, 1);
3232001f49Smrg   glVertex3d(-1, -1, 0);
3332001f49Smrg   glVertex3d(+1, -1, 0);
3432001f49Smrg   glVertex3d(+1, +1, 0);
3532001f49Smrg   glVertex3d(-1, +1, 0);
3632001f49Smrg   glEnd();
3732001f49Smrg
3832001f49Smrg   glPopMatrix();
3932001f49Smrg
4032001f49Smrg   glutSwapBuffers();
4132001f49Smrg}
4232001f49Smrg
4332001f49Smrg
4432001f49Smrgstatic void
4532001f49Smrgtimer(int value)
4632001f49Smrg{
4732001f49Smrg   angle += angle_delta;
4832001f49Smrg   glutTimerFunc(timeout, timer, 0);
4932001f49Smrg   glutPostRedisplay();
5032001f49Smrg}
5132001f49Smrg
5232001f49Smrg
5332001f49Smrgstatic void
5432001f49Smrgkey(unsigned char key, int x, int y)
5532001f49Smrg{
5632001f49Smrg   if (key == 27) {
5732001f49Smrg      exit(0);
5832001f49Smrg   }
5932001f49Smrg}
6032001f49Smrg
6132001f49Smrg
6232001f49Smrgint
6332001f49Smrgmain(int argc, char **argv)
6432001f49Smrg{
6532001f49Smrg   /* init glut */
6632001f49Smrg   glutInit(&argc, argv);
6732001f49Smrg   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
6832001f49Smrg   glutCreateWindow("Backface specular test");
6932001f49Smrg   glutDisplayFunc(display);
7032001f49Smrg   glutKeyboardFunc(key);
7132001f49Smrg   if (autorotate)
7232001f49Smrg      glutTimerFunc(timeout, timer, 0);
7332001f49Smrg
7432001f49Smrg   /* setup lighting */
7532001f49Smrg   glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
7632001f49Smrg   glMaterialfv(GL_BACK,  GL_DIFFUSE, diffuseb);
7732001f49Smrg
7832001f49Smrg   glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION,  black);
7932001f49Smrg   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,  specular);
8032001f49Smrg   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,   ambient);
8132001f49Smrg   glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shininess);
8232001f49Smrg
8332001f49Smrg   glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
8432001f49Smrg   glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
8532001f49Smrg   glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
8632001f49Smrg
8732001f49Smrg   glLightfv(GL_LIGHT0, GL_AMBIENT,  black);
8832001f49Smrg   glLightfv(GL_LIGHT0, GL_DIFFUSE,  white);
8932001f49Smrg   glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
9032001f49Smrg   glLightfv(GL_LIGHT0, GL_SPECULAR, white);
9132001f49Smrg
9232001f49Smrg   glDisable(GL_CULL_FACE);
9332001f49Smrg   glEnable(GL_LIGHTING);
9432001f49Smrg   glEnable(GL_LIGHT0);
9532001f49Smrg
9632001f49Smrg   /* setup camera */
9732001f49Smrg   glMatrixMode(GL_PROJECTION);
9832001f49Smrg   gluPerspective(30.0, 1.0, 1.0, 10.0);
9932001f49Smrg   glMatrixMode(GL_MODELVIEW);
10032001f49Smrg   gluLookAt(0.0, 0.0, 5.0,
10132001f49Smrg             0.0, 0.0, 0.0,
10232001f49Smrg             0.0, 1.0, 0.0);
10332001f49Smrg
10432001f49Smrg   /* setup misc */
10532001f49Smrg   glEnable(GL_DEPTH_TEST);
10632001f49Smrg   glClearColor(0, 0, 1, 1);
10732001f49Smrg
10832001f49Smrg   /* run */
10932001f49Smrg   glutMainLoop();
11032001f49Smrg
11132001f49Smrg   return 0;
11232001f49Smrg}
113