Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

renormal.c 2.6KB

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