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