132001f49Smrg 232001f49Smrg/* 332001f49Smrg * Test GL_EXT_rescale_normal extension 432001f49Smrg * Brian Paul January 1998 This program is in the public domain. 532001f49Smrg */ 632001f49Smrg 732001f49Smrg#include <stdio.h> 832001f49Smrg#include <stdlib.h> 932001f49Smrg#include <math.h> 1032001f49Smrg#include <GL/glew.h> /* for GL_RESCALE_NORMAL_EXT */ 1132001f49Smrg#include "glut_wrap.h" 1232001f49Smrg 1332001f49Smrg 1432001f49Smrgstatic GLfloat Phi = 0.0; 1532001f49Smrg 1632001f49Smrg 1732001f49Smrgstatic void Idle( void ) 1832001f49Smrg{ 1932001f49Smrg static double t0 = -1.; 2032001f49Smrg double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; 2132001f49Smrg if (t0 < 0.0) 2232001f49Smrg t0 = t; 2332001f49Smrg dt = t - t0; 2432001f49Smrg t0 = t; 2532001f49Smrg Phi += 3.0 * dt; 2632001f49Smrg glutPostRedisplay(); 2732001f49Smrg} 2832001f49Smrg 2932001f49Smrg 3032001f49Smrgstatic void Display( void ) 3132001f49Smrg{ 3232001f49Smrg GLfloat scale = 0.6 + 0.5 * sin(Phi); 3332001f49Smrg glClear( GL_COLOR_BUFFER_BIT ); 3432001f49Smrg glPushMatrix(); 3532001f49Smrg glScalef(scale, scale, scale); 3632001f49Smrg glutSolidSphere(2.0, 20, 20); 3732001f49Smrg glPopMatrix(); 3832001f49Smrg glutSwapBuffers(); 3932001f49Smrg} 4032001f49Smrg 4132001f49Smrg 4232001f49Smrgstatic void Reshape( int width, int height ) 4332001f49Smrg{ 4432001f49Smrg glViewport( 0, 0, width, height ); 4532001f49Smrg glMatrixMode( GL_PROJECTION ); 4632001f49Smrg glLoadIdentity(); 4732001f49Smrg glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); 4832001f49Smrg glMatrixMode( GL_MODELVIEW ); 4932001f49Smrg glLoadIdentity(); 5032001f49Smrg glTranslatef( 0.0, 0.0, -15.0 ); 5132001f49Smrg} 5232001f49Smrg 5332001f49Smrg 5432001f49Smrg 5532001f49Smrgstatic void Init( void ) 5632001f49Smrg{ 5732001f49Smrg static GLfloat mat[4] = { 0.8, 0.8, 0.0, 1.0 }; 5832001f49Smrg static GLfloat pos[4] = { -1.0, 1.0, 1.0, 0.0 }; 5932001f49Smrg 6032001f49Smrg /* setup lighting, etc */ 6132001f49Smrg glEnable(GL_LIGHTING); 6232001f49Smrg glEnable(GL_LIGHT0); 6332001f49Smrg glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat); 6432001f49Smrg glLightfv(GL_LIGHT0, GL_POSITION, pos); 6532001f49Smrg 6632001f49Smrg glEnable(GL_CULL_FACE); 6732001f49Smrg 6832001f49Smrg glDisable(GL_RESCALE_NORMAL_EXT); 6932001f49Smrg glDisable(GL_NORMALIZE); 7032001f49Smrg} 7132001f49Smrg 7232001f49Smrg 7332001f49Smrg#define UNSCALED 1 7432001f49Smrg#define NORMALIZE 2 7532001f49Smrg#define RESCALE 3 7632001f49Smrg#define QUIT 4 7732001f49Smrg 7832001f49Smrg 7932001f49Smrgstatic void ModeMenu(int entry) 8032001f49Smrg{ 8132001f49Smrg if (entry==UNSCALED) { 8232001f49Smrg glDisable(GL_RESCALE_NORMAL_EXT); 8332001f49Smrg glDisable(GL_NORMALIZE); 8432001f49Smrg } 8532001f49Smrg else if (entry==NORMALIZE) { 8632001f49Smrg glEnable(GL_NORMALIZE); 8732001f49Smrg glDisable(GL_RESCALE_NORMAL_EXT); 8832001f49Smrg } 8932001f49Smrg else if (entry==RESCALE) { 9032001f49Smrg glDisable(GL_NORMALIZE); 9132001f49Smrg glEnable(GL_RESCALE_NORMAL_EXT); 9232001f49Smrg } 9332001f49Smrg else if (entry==QUIT) { 9432001f49Smrg exit(0); 9532001f49Smrg } 9632001f49Smrg glutPostRedisplay(); 9732001f49Smrg} 9832001f49Smrg 9932001f49Smrgstatic void 10032001f49Smrgkey(unsigned char k, int x, int y) 10132001f49Smrg{ 10232001f49Smrg (void) x; 10332001f49Smrg (void) y; 10432001f49Smrg switch (k) { 10532001f49Smrg case 27: /* Escape */ 10632001f49Smrg exit(0); 10732001f49Smrg break; 10832001f49Smrg default: 10932001f49Smrg return; 11032001f49Smrg } 11132001f49Smrg glutPostRedisplay(); 11232001f49Smrg} 11332001f49Smrg 11432001f49Smrgint main( int argc, char *argv[] ) 11532001f49Smrg{ 11632001f49Smrg glutInitWindowSize( 400, 400 ); 11732001f49Smrg glutInit( &argc, argv ); 11832001f49Smrg glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); 11932001f49Smrg glutCreateWindow(argv[0]); 12032001f49Smrg 12132001f49Smrg Init(); 12232001f49Smrg 12332001f49Smrg glutIdleFunc( Idle ); 12432001f49Smrg glutReshapeFunc( Reshape ); 12532001f49Smrg glutDisplayFunc( Display ); 12632001f49Smrg glutKeyboardFunc(key); 12732001f49Smrg 12832001f49Smrg glutCreateMenu(ModeMenu); 12932001f49Smrg glutAddMenuEntry("Unscaled", UNSCALED); 13032001f49Smrg glutAddMenuEntry("Normalize", NORMALIZE); 13132001f49Smrg glutAddMenuEntry("Rescale EXT", RESCALE); 13232001f49Smrg glutAddMenuEntry("Quit", QUIT); 13332001f49Smrg glutAttachMenu(GLUT_RIGHT_BUTTON); 13432001f49Smrg 13532001f49Smrg glutMainLoop(); 13632001f49Smrg return 0; 13732001f49Smrg} 138