Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #include <GL/gl.h>
  2. #include <GL/glu.h>
  3.  
  4. #include <freeglut.h>
  5.  
  6.  
  7. static GLfloat spin = 0.0;
  8.  
  9. void init(void)
  10. {
  11.     glClearColor(0.0, 0.0, 0.0, 0.0);
  12.     glShadeModel(GL_FLAT);
  13. }
  14.  
  15. void display(void)
  16. {
  17.     glClear(GL_COLOR_BUFFER_BIT);
  18.     glPushMatrix();
  19.     glRotatef(spin, 0.0, 0.0, 1.0);
  20.     glColor3f(1.0, 1.0, 1.0);
  21.     glRectf(-25.0, -25.0, 25.0, 25.0);
  22.     glPopMatrix();
  23.     glutSwapBuffers();
  24. }
  25.  
  26. void spinDisplay(void)
  27. {
  28.     spin = spin + 2.0;
  29.     if (spin > 360.0)
  30.         spin = spin - 360.0;
  31.     glutPostRedisplay();
  32. }
  33.  
  34. void reshape(int w, int h)
  35. {
  36.     glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  37.     glMatrixMode(GL_PROJECTION);
  38.     glLoadIdentity();
  39.     glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
  40.     glMatrixMode(GL_MODELVIEW);
  41.     glLoadIdentity();
  42. }
  43.  
  44. void mouse(int button, int state, int x, int y)
  45. {
  46.     switch (button) {
  47.         case GLUT_LEFT_BUTTON:
  48.             if (state == GLUT_DOWN)
  49.             glutIdleFunc(spinDisplay);
  50.         break;
  51.             case GLUT_MIDDLE_BUTTON:
  52.             if (state == GLUT_DOWN)
  53.                 glutIdleFunc(NULL);
  54.             break;
  55.         default:
  56.             break;
  57.     }
  58. }
  59.  
  60. /*
  61. * Request double buffer display mode.
  62. * Register mouse input callback functions
  63. */
  64. int main(int argc, char** argv)
  65. {
  66.     glutInit(&argc, argv);
  67.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  68.     glutInitWindowSize(250, 250);
  69.     glutInitWindowPosition(100, 100);
  70.     glutCreateWindow(argv[0]);
  71.     init();
  72.    
  73.     glutDisplayFunc(display);
  74.     glutReshapeFunc(reshape);
  75.     glutMouseFunc(mouse);
  76.    
  77.     glutMainLoop();
  78.    
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement