Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 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. GLfloat angle = 0.0f;
  24.  
  25. int refreshMillis = 300;
  26.  
  27. void initGL()
  28. {
  29. glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  30. }
  31.  
  32. void idle() {
  33. glutPostRedisplay();
  34. }
  35.  
  36. void display() {
  37. glClear(GL_COLOR_BUFFER_BIT);
  38. glMatrixMode(GL_MODELVIEW);
  39. glLoadIdentity();
  40.  
  41. glPushMatrix();
  42. glTranslatef(0.0f, 0.0f, 0.0f);
  43. glRotatef(angle, 1.0f, 1.0f, 0.0f);
  44.  
  45. glBegin(GL_QUADS);
  46. glColor3ub(0, 255, 0);
  47. glVertex2f(-0.3f, -0.3f);
  48. glVertex2f(0.3f, -0.3f);
  49. glVertex2f(0.3f, 0.3f);
  50. glVertex2f(-0.3f, 0.3f);
  51. glEnd();
  52. glPopMatrix();
  53.  
  54.  
  55.  
  56. glutSwapBuffers();
  57. //glFlush();
  58. angle += 1.9f;
  59.  
  60. }
  61.  
  62. void reshape(GLsizei width, GLsizei height = 1)
  63. {
  64. if (height == 0) height = 1;
  65. GLfloat aspect = (GLfloat)width / (GLfloat)height;
  66.  
  67. glViewport(0,0, width, height);
  68.  
  69. glMatrixMode(GL_PROJECTION);
  70. glLoadIdentity();
  71. if(width >= height)
  72. {
  73. gluOrtho2D(-1.0 * aspect,
  74. 1.0 * aspect,
  75. -1.0, 1.0);
  76. }
  77. }
  78.  
  79. void Timer(int value)
  80. {
  81. glutPostRedisplay();
  82. glutTimerFunc(refreshMillis, Timer, 0);
  83. }
  84.  
  85. int main(int argc, char *argv[])
  86. {
  87. glutInit(&argc, argv);
  88. glutInitDisplayMode(GLUT_DOUBLE);
  89. glutCreateWindow("Zadanie 4.1");
  90. glutInitWindowSize(600,600);
  91. glutInitWindowPosition(300,300);
  92. glutDisplayFunc(display);
  93. glutReshapeFunc(reshape);
  94. //glutIdleFunc(idle);
  95. glutTimerFunc(0, Timer, 0);
  96. initGL();
  97. glutMainLoop();
  98.  
  99. return EXIT_SUCCESS;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement