Advertisement
Guest User

Untitled

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