MarouaneTheViper

Rotating Letter L

Mar 26th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include <math.h>
  4. #define GL_GLEXT_PROTOTYPES
  5. #include <GL/glut.h> gl.h
  6.  
  7. double rotate_y=0;
  8. double rotate_x=0;
  9.  
  10. void display ()
  11. {
  12. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  13. glLoadIdentity();
  14. glRotatef( rotate_x, 1.0, 0.0, 0.0 );
  15. glRotatef( rotate_y, 0.0, 1.0, 0.0 );
  16. glBegin(GL_QUADS);
  17. glColor3f(1.0,0.0,1.0);
  18. glVertex3f(0.2, 0.0, -0.5);
  19. glVertex3f(1.0, 0.0, -0.5);
  20. glVertex3f(1.0, 0.2, -0.5);
  21. glVertex3f(0.2, 0.2, -0.5);
  22. glEnd();
  23. glBegin(GL_QUADS);
  24. glColor3f(1.0,0.0,1.0);
  25. glVertex3f(0.0, 0.0, -0.5);
  26. glVertex3f(0.2, 0.0, -0.5);
  27. glVertex3f(0.2, 1.0, -0.5);
  28. glVertex3f(0.0, 1.0, -0.5);
  29. glEnd();
  30. glBegin(GL_QUADS);
  31. glColor3f(1.0,0.0,1.0);
  32. glVertex3f(0.2, 0.0, 0.0);
  33. glVertex3f(1.0, 0.0, 0.0);
  34. glVertex3f(1.0, 0.2, 0.0);
  35. glVertex3f(0.2, 0.2, 0.0);
  36. glEnd();
  37. glBegin(GL_QUADS);
  38. glColor3f(1.0,0.0,1.0);
  39. glVertex3f(0.0, 0.0, 0.0);
  40. glVertex3f(0.2, 0.0, 0.0);
  41. glVertex3f(0.2, 1.0, 0.0);
  42. glVertex3f(0.0, 1.0, 0.0);
  43. glEnd();
  44. glBegin(GL_QUADS);
  45. glColor3f(1.0,0.0,1.0);
  46. glVertex3f(0.2, 1.0, 0.0);
  47. glVertex3f(0.0, 1.0, 0.0);
  48. glVertex3f(0.0, 1.0, -0.5);
  49. glVertex3f(0.2, 1.0, -0.5);
  50. glEnd();
  51. glBegin(GL_QUADS);
  52. glColor3f(1.0,0.0,1.0);
  53. glVertex3f(0.0, 0.0, 0.0);
  54. glVertex3f(0.2, 0.0, 0.0);
  55. glVertex3f(0.2, 0.0, -0.5);
  56. glVertex3f(0.0, 0.0, -0.5);
  57. glEnd();
  58. glBegin(GL_QUADS);
  59. glColor3f(1.0,0.0,1.0);
  60. glVertex3f(0.2, 0.2, 0.0);
  61. glVertex3f(1.0, 0.2, 0.0);
  62. glVertex3f(1.0, 0.2, -0.5);
  63. glVertex3f(0.2, 0.2, -0.5);
  64. glEnd();
  65. glBegin(GL_QUADS);
  66. glColor3f(1.0,0.0,1.0);
  67. glVertex3f(0.2, 0.0, 0.0);
  68. glVertex3f(1.0, 0.0, 0.0);
  69. glVertex3f(1.0, 0.0, -0.5);
  70. glVertex3f(0.2, 0.0, -0.5);
  71. glEnd();
  72. glBegin(GL_QUADS);
  73. glColor3f(1.0,0.0,1.0);
  74. glVertex3f(1.0, 0.2, 0.0);
  75. glVertex3f(1.0, 0.0, 0.0);
  76. glVertex3f(1.0, 0.0, -0.5);
  77. glVertex3f(1.0, 0.2, -0.5);
  78. glEnd();
  79. glBegin(GL_QUADS);
  80. glColor3f(1.0,0.0,1.0);
  81. glVertex3f(0.0, 0.0, 0.0);
  82. glVertex3f(0.0, 1.0, 0.0);
  83. glVertex3f(0.0, 1.0, -0.5);
  84. glVertex3f(0.0, 0.0, -0.5);
  85. glEnd();
  86. glFlush();
  87. glutSwapBuffers();
  88. }
  89.  
  90.  
  91. void init(void)
  92. {
  93. glClearColor(0,0,0,0);
  94. glMatrixMode(GL_PROJECTION);
  95. glLoadIdentity();
  96. gluOrtho2D(-320, 319,-240, 239);
  97. glClear(GL_COLOR_BUFFER_BIT);
  98.  
  99. glFlush();
  100. }
  101.  
  102. void keys( int key, int x, int y )
  103. {
  104. if(key==GLUT_KEY_RIGHT)
  105. {
  106. rotate_y=rotate_y+5;
  107. }
  108. if(key==GLUT_KEY_LEFT)
  109. {
  110. rotate_y=rotate_y-5;
  111. }
  112. if(key==GLUT_KEY_UP)
  113. {
  114. rotate_x=rotate_x+5;
  115. }
  116. if(key==GLUT_KEY_DOWN)
  117. {
  118. rotate_x=rotate_x-5;
  119. }
  120. glutPostRedisplay();
  121. }
  122.  
  123. void reshape(GLsizei width, GLsizei height)
  124. {
  125. if (height == 0)
  126. height = 1;
  127. GLfloat aspect = (GLfloat)width / (GLfloat)height;
  128. glViewport(0, 0, width, height);
  129. glMatrixMode(GL_PROJECTION);
  130. glLoadIdentity();
  131. if (width >= height)
  132. {
  133.  
  134. gluOrtho2D(-1.0 * aspect, 1.0 * aspect, -1.0, 1.0);
  135. }
  136. else
  137. {
  138. gluOrtho2D(-1.0, 1.0, -1.0 / aspect, 1.0 / aspect);
  139. }
  140. }
  141. void keyboard(unsigned char key, int x, int y) {
  142. }
  143.  
  144. int main(int argc, char* argv[])
  145. {
  146. glutInit(&argc,argv);
  147. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  148. glutCreateWindow("Rotating Letter L");
  149. glEnable(GL_DEPTH_TEST);
  150. glutDisplayFunc(display);
  151. glutReshapeFunc(reshape);
  152. glutSpecialFunc(keys);
  153. glutKeyboardFunc(keyboard);
  154. glutMainLoop();
  155. return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment