Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <GL/gl.h>
  3. #include <GL/glu.h>
  4. #include <GL/glut.h>
  5.  
  6. static int width;
  7. static int height;
  8. GLfloat zSpin;
  9.  
  10. void init()
  11. {
  12. glClearColor(0, 0, 0, 0);
  13. glEnable(GL_DEPTH_TEST);
  14. glMatrixMode(GL_PROJECTION);
  15. glOrtho(-3, 3, -3, 3, 1, 50);
  16. glLoadIdentity();
  17. }
  18. void display()
  19. {
  20. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  21.  
  22.  
  23. glViewport(0, height / 2, width / 2, height / 2);
  24. glMatrixMode(GL_PROJECTION);
  25. glOrtho(-3, 3, -3, 3, 1, 50);
  26. glLoadIdentity();
  27. glColor3f(1.0f, 0, 0);
  28. glMatrixMode(GL_MODELVIEW);
  29. glLoadIdentity();
  30. gluLookAt(0.0f, -0.5f, 0.0f,
  31. 0.0f, 0.0f, 0.0f,
  32. 0.0f, 0.0f, 1.0f);
  33. glutWireTeapot(0.5f);
  34.  
  35. glViewport(width / 2, height / 2, width / 2, height / 2);
  36. glMatrixMode(GL_PROJECTION);
  37. glOrtho(-3, 3, -3, 3, 1, 50);
  38. glLoadIdentity();
  39. glColor3f(1.0f, 0, 0);
  40. glMatrixMode(GL_MODELVIEW);
  41. glLoadIdentity();
  42. gluLookAt(1.0f, 0.0f, 0.0f,
  43. 0.0f, 0.0f, 0.0f,
  44. 0.0f, 1.0f, 0.0f);
  45. glutWireTeapot(0.5f);
  46.  
  47. glViewport(0, 0, width / 2, height / 2);
  48. glMatrixMode(GL_PROJECTION);
  49. glOrtho(-3, 3, -3, 3, 1, 50);
  50. glLoadIdentity();
  51. glMatrixMode(GL_MODELVIEW);
  52. glLoadIdentity();
  53. glColor3f(1.0f, 0, 0);
  54. glutWireTeapot(0.5f);
  55.  
  56. glViewport(width / 2, 0, width / 2, height / 2);
  57. //glMatrixMode(GL_PROJECTION);
  58. gluPerspective(70, 1, 1, 50);
  59. glLoadIdentity();
  60. //glMatrixMode(GL_MODELVIEW);
  61. glLoadIdentity();
  62. glRotatef(zSpin, 0, 0, 1.0);
  63. glRotatef(45, 1, 0, 0);
  64. glColor3f(1.0f, 0, 0);
  65. glutWireTeapot(0.5f);
  66.  
  67. glFlush();
  68. }
  69. void reshape(int w, int h)
  70. {
  71. width = w;
  72. height = h;
  73. glViewport(0, 0, width, height);
  74. }
  75. void rotationFunc(void){
  76. zSpin +=0.3;
  77. display();
  78. }
  79. int main(int argc, char **argv)
  80. {
  81. glutInit(&argc, argv);
  82. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  83.  
  84. int screen_Width = (glutGet(GLUT_SCREEN_WIDTH) - 640) / 2;
  85. int screen_Height = (glutGet(GLUT_SCREEN_HEIGHT) - 480) / 2;
  86. glutInitWindowPosition(screen_Width, screen_Height);
  87. glutInitWindowSize(800, 800);
  88. glutCreateWindow("Bonus 2");
  89.  
  90. init();
  91. glutDisplayFunc(display);
  92. glutReshapeFunc(reshape);
  93. glutIdleFunc(rotationFunc);
  94. glutMainLoop();
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement