blob: 284dffdb2747b6ac8d4051b36433f8a5efa85643 [file] [log] [blame]
jtgafb833d1999-08-19 00:55:39 +00001
2/*
3 * Test GL_EXT_rescale_normal extension
4 * Brian Paul January 1998 This program is in the public domain.
5 */
6
jtgafb833d1999-08-19 00:55:39 +00007#include <stdio.h>
8#include <stdlib.h>
9#include <math.h>
10#include <GL/glut.h>
11
12
13static GLfloat Phi = 0.0;
14
15
16static void Idle(void)
17{
18 Phi += 0.1;
19 glutPostRedisplay();
20}
21
22
23static 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
35static 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
48static 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
72static 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
Ted Jump83c02ef1999-09-17 02:40:51 +000092static void
93key(unsigned char k, int x, int y)
94{
Brian Paulecaf1a01999-09-17 12:27:01 +000095 (void) x;
96 (void) y;
Ted Jump83c02ef1999-09-17 02:40:51 +000097 switch (k) {
98 case 27: /* Escape */
99 exit(0);
100 break;
101 default:
102 return;
103 }
104 glutPostRedisplay();
105}
jtgafb833d1999-08-19 00:55:39 +0000106
107int 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 );
Ted Jump83c02ef1999-09-17 02:40:51 +0000121 glutKeyboardFunc(key);
jtgafb833d1999-08-19 00:55:39 +0000122
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}