CzarnyBarszcz

kulka

Apr 18th, 2021
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. /*
  2. * GLUT Shapes Demo
  3. *
  4. * Written by Nigel Stewart November 2003
  5. *
  6. * This program is test harness for the sphere, cone
  7. * and torus shapes in GLUT.
  8. *
  9. * Spinning wireframe and smooth shaded shapes are
  10. * displayed until the ESC or q key is pressed. The
  11. * number of geometry stacks and slices can be adjusted
  12. * using the + and - keys.
  13. */
  14. #include <windows.h>
  15. #ifdef __APPLE__
  16. #include <GLUT/glut.h>
  17. #else
  18. #include <GL/glut.h>
  19. #endif
  20.  
  21. #include <stdlib.h>
  22.  
  23. static int slices = 16;
  24. static int stacks = 16;
  25.  
  26. /* GLUT callback Handlers */
  27.  
  28. static void resize(int width, int height)
  29. {
  30. const float ar = (float) width / (float) height;
  31.  
  32. glViewport(0, 0, width, height);
  33. glMatrixMode(GL_PROJECTION);
  34. glLoadIdentity();
  35. glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
  36.  
  37. glMatrixMode(GL_MODELVIEW);
  38. glLoadIdentity() ;
  39. }
  40.  
  41. static void display(void)
  42. {
  43. const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
  44. const double a = t*90.0;
  45.  
  46. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  47. glColor3d(1,1,1);
  48.  
  49. glPushMatrix();
  50. glTranslated(0,0,-6);
  51. glutSolidSphere(1,36,36);
  52. glPopMatrix();
  53.  
  54.  
  55. glutSwapBuffers();
  56. }
  57.  
  58.  
  59. static void key(unsigned char key, int x, int y)
  60. {
  61. switch (key)
  62. {
  63. case 27 :
  64. case 'q':
  65. exit(0);
  66. break;
  67.  
  68. case '+':
  69. slices++;
  70. stacks++;
  71. break;
  72.  
  73. case '-':
  74. if (slices>3 && stacks>3)
  75. {
  76. slices--;
  77. stacks--;
  78. }
  79. break;
  80. }
  81.  
  82. glutPostRedisplay();
  83. }
  84.  
  85. static void idle(void)
  86. {
  87. glutPostRedisplay();
  88. }
  89.  
  90. const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
  91. const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  92. const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  93. const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
  94.  
  95. const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
  96. const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
  97. const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  98. const GLfloat high_shininess[] = { 100.0f };
  99.  
  100. /* Program entry point */
  101.  
  102. int main(int argc, char *argv[])
  103. {
  104. glutInit(&argc, argv);
  105. glutInitWindowSize(640,480);
  106. glutInitWindowPosition(10,10);
  107. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  108.  
  109. glutCreateWindow("GLUT Shapes");
  110.  
  111. glutReshapeFunc(resize);
  112. glutDisplayFunc(display);
  113. glutKeyboardFunc(key);
  114. glutIdleFunc(idle);
  115.  
  116. glClearColor(0,0,0,1);
  117. glEnable(GL_CULL_FACE);
  118. glCullFace(GL_BACK);
  119.  
  120. glEnable(GL_DEPTH_TEST);
  121. glDepthFunc(GL_LESS);
  122.  
  123. glEnable(GL_LIGHT0);
  124. glEnable(GL_NORMALIZE);
  125. glEnable(GL_COLOR_MATERIAL);
  126. glEnable(GL_LIGHTING);
  127.  
  128. glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
  129. glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  130. glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
  131. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  132.  
  133. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  134. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  135. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  136. glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
  137.  
  138. glutMainLoop();
  139.  
  140. return EXIT_SUCCESS;
  141. }
  142.  
Advertisement
Add Comment
Please, Sign In to add comment