home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / demos / renormal.c < prev    next >
C/C++ Source or Header  |  2000-01-07  |  3KB  |  139 lines

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