MarouaneTheViper

Untitled

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