Removed all RCS / CVS tags (Id, Header, Date, etc.) from everything.
[mesa.git] / progs / demos / renormal.c
1
2 /*
3 * Test GL_EXT_rescale_normal extension
4 * Brian Paul January 1998 This program is in the public domain.
5 */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <math.h>
10 #include <GL/glut.h>
11
12
13 static GLfloat Phi = 0.0;
14
15
16 static void Idle(void)
17 {
18 Phi += 0.1;
19 glutPostRedisplay();
20 }
21
22
23 static void Display( void )
24 {
25 GLfloat scale = 0.6 + 0.5 * sin(Phi);
26 glClear( GL_COLOR_BUFFER_BIT );
27 glPushMatrix();
28 glScalef(scale, scale, scale);
29 glutSolidSphere(2.0, 20, 20);
30 glPopMatrix();
31 glutSwapBuffers();
32 }
33
34
35 static void Reshape( int width, int height )
36 {
37 glViewport( 0, 0, width, height );
38 glMatrixMode( GL_PROJECTION );
39 glLoadIdentity();
40 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
41 glMatrixMode( GL_MODELVIEW );
42 glLoadIdentity();
43 glTranslatef( 0.0, 0.0, -15.0 );
44 }
45
46
47
48 static void Init( void )
49 {
50 static GLfloat mat[4] = { 0.8, 0.8, 0.0, 1.0 };
51 static GLfloat pos[4] = { -1.0, 1.0, 1.0, 0.0 };
52
53 /* setup lighting, etc */
54 glEnable(GL_LIGHTING);
55 glEnable(GL_LIGHT0);
56 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat);
57 glLightfv(GL_LIGHT0, GL_POSITION, pos);
58
59 glEnable(GL_CULL_FACE);
60
61 glDisable(GL_RESCALE_NORMAL_EXT);
62 glDisable(GL_NORMALIZE);
63 }
64
65
66 #define UNSCALED 1
67 #define NORMALIZE 2
68 #define RESCALE 3
69 #define QUIT 4
70
71
72 static void ModeMenu(int entry)
73 {
74 if (entry==UNSCALED) {
75 glDisable(GL_RESCALE_NORMAL_EXT);
76 glDisable(GL_NORMALIZE);
77 }
78 else if (entry==NORMALIZE) {
79 glEnable(GL_NORMALIZE);
80 glDisable(GL_RESCALE_NORMAL_EXT);
81 }
82 else if (entry==RESCALE) {
83 glDisable(GL_NORMALIZE);
84 glEnable(GL_RESCALE_NORMAL_EXT);
85 }
86 else if (entry==QUIT) {
87 exit(0);
88 }
89 glutPostRedisplay();
90 }
91
92 static void
93 key(unsigned char k, int x, int y)
94 {
95 (void) x;
96 (void) y;
97 switch (k) {
98 case 27: /* Escape */
99 exit(0);
100 break;
101 default:
102 return;
103 }
104 glutPostRedisplay();
105 }
106
107 int main( int argc, char *argv[] )
108 {
109 glutInit( &argc, argv );
110 glutInitWindowSize( 400, 400 );
111
112 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
113
114 glutCreateWindow(argv[0]);
115
116 Init();
117
118 glutIdleFunc( Idle );
119 glutReshapeFunc( Reshape );
120 glutDisplayFunc( Display );
121 glutKeyboardFunc(key);
122
123 glutCreateMenu(ModeMenu);
124 glutAddMenuEntry("Unscaled", UNSCALED);
125 glutAddMenuEntry("Normalize", NORMALIZE);
126 glutAddMenuEntry("Rescale EXT", RESCALE);
127 glutAddMenuEntry("Quit", QUIT);
128 glutAttachMenu(GLUT_RIGHT_BUTTON);
129
130 glutMainLoop();
131 return 0;
132 }