MarouaneTheViper

Rotating Letter V

Mar 26th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #ifdef __APPLE__
  2. #include <GLUT/glut.h>
  3. #else
  4. #include <GL/glut.h>
  5. #endif
  6.  
  7. #include <stdlib.h>
  8.  
  9. double rotate_y=0;
  10. double rotate_x=0;
  11. int angle = 0;
  12.  
  13. void display(void)
  14. {
  15. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  16. glMatrixMode(GL_MODELVIEW);
  17. glLoadIdentity();
  18. glRotatef( rotate_x, 1.0, 0.0, 0.0 );
  19. glRotatef( rotate_y, 0.0, 1.0, 0.0 );
  20. glRotatef(180+angle, 0, 0, 1);
  21. glScalef(0.5f,0.5f,0.5f);
  22. glLineWidth(4.0);
  23. glBegin(GL_QUAD_STRIP);
  24. glColor3f(1.0f,0.0f,1.0f);
  25. glVertex3i(1,1,0);
  26. glVertex3i(1,1,-1);
  27. glVertex3i(0,0,-1);
  28. glVertex3i(0,0,0);
  29. glVertex3i(-1,1,0);
  30. glVertex3i(-1,1,-1);
  31. glEnd();
  32. glLoadIdentity();
  33. glutSwapBuffers();
  34. }
  35.  
  36. void mouse(int button, int state, int x, int y) {
  37. switch (button) {
  38. case GLUT_LEFT_BUTTON:
  39. if (state == GLUT_DOWN)
  40. exit(0);
  41. break;
  42. case GLUT_RIGHT_BUTTON:
  43. angle += 10;
  44. break;
  45. }
  46. }
  47.  
  48. void keyboard(unsigned char key, int x,int y)
  49. {}
  50.  
  51. static void idle(void)
  52. {
  53. glutPostRedisplay();
  54. }
  55.  
  56. void keys( int key, int x, int y )
  57. {
  58. if(key==GLUT_KEY_RIGHT)
  59. {
  60. rotate_y=rotate_y+5;
  61. }
  62. if(key==GLUT_KEY_LEFT)
  63. {
  64. rotate_y=rotate_y-5;
  65. }
  66. if(key==GLUT_KEY_UP)
  67. {
  68. rotate_x=rotate_x+5;
  69. }
  70. if(key==GLUT_KEY_DOWN)
  71. {
  72. rotate_x=rotate_x-5;
  73. }
  74. glutPostRedisplay();
  75. }
  76.  
  77. int main(int argc, char *argv[])
  78. {
  79. glutInit(&argc, argv);
  80. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  81. glutInitWindowSize(900, 900);
  82. glutInitWindowPosition (100, 100);
  83. glutCreateWindow("Assignment 1");
  84. glutDisplayFunc(display);
  85. glutMouseFunc(mouse);
  86. glutKeyboardFunc(keyboard);
  87. glutSpecialFunc(keys);
  88. glutIdleFunc(idle);
  89. glutMainLoop();
  90. return EXIT_SUCCESS;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment