Clone of mesa.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

renormal.c 2.4KB

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