Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 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.  
  15. #ifdef __APPLE__
  16. #include <GLUT/glut.h>
  17. #else
  18. #include <GL/glut.h>
  19. #endif
  20.  
  21. #include <stdlib.h>
  22.  
  23. float counter = 0;
  24.  
  25. /* GLUT callback Handlers */
  26.  
  27. void reshape(GLsizei width, GLsizei height){
  28. if (height == 0) height = 1;
  29. GLfloat aspect = (GLfloat)width / (GLfloat)height;
  30. glViewport(0, 0, width, height);
  31. glMatrixMode(GL_PROJECTION);
  32. glLoadIdentity();
  33. gluPerspective(60.0f, aspect, 0.1f, 100.0f);
  34.  
  35. }
  36. void initOpenGL(){
  37. glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  38. glClearDepth(1.0f);
  39. glEnable(GL_DEPTH_TEST);
  40. glDepthFunc(GL_LEQUAL);
  41. glShadeModel(GL_SMOOTH);
  42. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  43.  
  44. }
  45. void display(){
  46.  
  47.  
  48. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  49. glMatrixMode(GL_MODELVIEW);
  50. glLoadIdentity();
  51. glTranslatef(0.0f, 0.0f, -7.0f);
  52. if(counter<360){
  53. glRotatef(counter, 1.0, 0.0, 0.0);
  54. }else{
  55. glRotatef(counter, 0.0, 1.0, 0.0);
  56. }
  57.  
  58. counter += 0.01;
  59. glBegin(GL_QUADS);
  60.  
  61. glColor3f(1.0f, 0.0f, 0.0f);
  62. glVertex3f( 1.0f, 1.0f, -1.0f);
  63. glVertex3f(-1.0f, 1.0f, -1.0f);
  64. glVertex3f(-1.0f, 1.0f, 1.0f);
  65. glVertex3f( 1.0f, 1.0f, 1.0f);
  66.  
  67. glColor3f(1.0f, 0.5f, 0.0f);
  68. glVertex3f( 1.0f, -1.0f, 1.0f);
  69. glVertex3f(-1.0f, -1.0f, 1.0f);
  70. glVertex3f(-1.0f, -1.0f, -1.0f);
  71. glVertex3f( 1.0f, -1.0f, -1.0f);
  72.  
  73. glColor3f(1.0f, 0.0f, 0.0f);
  74. glVertex3f( 1.0f, 1.0f, 1.0f);
  75. glVertex3f(-1.0f, 1.0f, 1.0f);
  76. glVertex3f(-1.0f, -1.0f, 1.0f);
  77. glVertex3f( 1.0f, -1.0f, 1.0f);
  78.  
  79. glColor3f(1.0f, 1.0f, 0.0f);
  80. glVertex3f(-1.0f, 1.0f, 1.0f);
  81. glVertex3f(-1.0f, 1.0f, -1.0f);
  82. glVertex3f(-1.0f, -1.0f, -1.0f);
  83. glVertex3f(-1.0f, -1.0f, 1.0f);
  84.  
  85. glColor3f(1.0f, 0.0f, 1.0f);
  86. glVertex3f(1.0f, 1.0f, -1.0f);
  87. glVertex3f(1.0f, 1.0f, 1.0f);
  88. glVertex3f(1.0f, -1.0f, 1.0f);
  89. glVertex3f(1.0f, -1.0f, -1.0f);
  90.  
  91. glEnd();
  92. glutSwapBuffers();
  93. }
  94.  
  95. int main(int argc, char** argv) {
  96. glutInit(&argc, argv);
  97. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
  98. glutInitWindowSize(640, 480);
  99. glutInitWindowPosition(50, 50);
  100. glutCreateWindow("Primitive");
  101. glutDisplayFunc(display);
  102. glutIdleFunc(display);
  103. glutReshapeFunc(reshape);
  104. initOpenGL();
  105. glutMainLoop();
  106. return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement