MarouaneTheViper

Untitled

May 24th, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #ifdef __APPLE__
  2. #include <GLUT/glut.h>
  3. #else
  4. #include <GL/glut.h>
  5. #endif
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. int angle = 0;
  10. int rotating = 0;
  11. GLfloat rotate_y = 0;
  12.  
  13. void display(void)
  14. {
  15. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  16. glLoadIdentity();
  17. if(rotating == 1){
  18. rotate_y += 0.2;
  19. }
  20. glRotatef(rotate_y, 0.0, 0.0, 1.0 );
  21. glTranslatef(-0.5,-0.5,0);
  22. glScalef(0.5f,0.5f,0.5f);
  23. glLineWidth(4.0);
  24. glBegin(GL_LINE_STRIP);
  25. glColor3f(1.0f,0.0f,1.0f);
  26. glVertex3i(0,0,0);
  27. glVertex3i(0,2,0);
  28. glVertex3i(1,1,0);
  29. glVertex3i(2,2,0);
  30. glVertex3i(2,0,0);
  31. glEnd();
  32. glLoadIdentity();
  33. glutSwapBuffers();
  34. }
  35.  
  36. //gwa mouse handler while loop
  37. //global var bool y3ne b rotat wla la2 w n3'yro gwa mouse handler 1 right 0 left
  38.  
  39. void mouse(int button, int state, int x, int y) {
  40. switch (button) {
  41. case GLUT_LEFT_BUTTON:
  42. rotating = 1;
  43. break;
  44. case GLUT_RIGHT_BUTTON:
  45. if(state == GLUT_DOWN)
  46. rotating = 0;
  47. break;
  48. }
  49. }
  50.  
  51. void keyboard(unsigned char key, int x,int y)
  52. {}
  53.  
  54. static void idle(void)
  55. {
  56. glutPostRedisplay();
  57. }
  58.  
  59. int main(int argc, char *argv[])
  60. {
  61. glutInit(&argc, argv);
  62. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  63. glutInitWindowSize(900, 900);
  64. glutInitWindowPosition (100, 100);
  65. glutCreateWindow("Rotating Letter");
  66. glutDisplayFunc(display);
  67. glutMouseFunc(mouse);
  68. glutKeyboardFunc(keyboard);
  69. glutIdleFunc(idle);
  70. glutMainLoop();
  71. return EXIT_SUCCESS;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment