Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 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.0;
  24. void square(float r, float g, float b){
  25. glColor3f(r, g, b);
  26. glBegin(GL_TRIANGLE_FAN);
  27. glVertex3f(-0.5, -0.5, 0.5);
  28. glVertex3f(0.5, -0.5, 0.5);
  29. glVertex3f(0.5, 0.5, 0.5);
  30. glVertex3f(-0.5, 0.5, 0.5);
  31. glEnd();
  32. }
  33. void cube(float size){
  34. glPushMatrix();
  35. glScalef(size, size, size);
  36.  
  37. square(1, 0, 0);
  38.  
  39. glPushMatrix();
  40. glRotatef(90, 0, 1, 0);
  41. square(0, 1, 0);
  42. glPopMatrix();
  43.  
  44. glPushMatrix();
  45. glRotatef(-90, 1, 0, 0);
  46. square(0, 0, 1);
  47. glPopMatrix();
  48.  
  49. glPushMatrix();
  50. glRotatef(180, 0, 1, 0);
  51. square(0, 1, 1);
  52. glPopMatrix();
  53.  
  54. }
  55. void circle(){
  56.  
  57.  
  58. }
  59.  
  60. void display (){
  61. glClear(GL_COLOR_BUFFER_BIT); //restart clear color
  62. glLoadIdentity();
  63. glPushMatrix();
  64. glTranslatef(0.5, 0.5, 0.0);
  65. circle();
  66. glPopMatrix();
  67.  
  68. glRotatef(counter, 1.0, 1.0, 1.0);
  69. counter += 0.01;
  70. cube(0.5);
  71.  
  72. glutSwapBuffers(); //interchange memory buffers
  73. }
  74.  
  75. void reshape(int width, int high){
  76. glViewport(0,0,width,high); //define where to draw the object
  77. }
  78.  
  79. void initOpenGL(){
  80. glClearColor(1.0, 0.0, 0.0, 1.0); //background color RGB black
  81. }
  82.  
  83.  
  84. int main (int argc, char **argv){
  85.  
  86. glutInit(&argc, argv);// initialize GLUT
  87. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); //double buffer, color RGB + alpha channel, & use depth for 3D
  88. glutInitWindowSize(500, 500); //windows size
  89. glutCreateWindow("Transformations"); //windows name
  90.  
  91. glutDisplayFunc(display);
  92. glutIdleFunc(display);
  93. glutReshapeFunc(reshape);
  94.  
  95. initOpenGL();
  96.  
  97. glutMainLoop();//activate infinite loop
  98.  
  99. return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement