didito33

Tanq Zad

Nov 13th, 2023
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. /*
  2. * GLUT Shapes Demo
  3. *
  4. * Written by Nigel Stewart November 2003
  5. *
  6. * This program is test harness for the sphere, cone
  7. * and torus shapes in GLUT.
  8. *
  9. * Spinning wireframe and smooth shaded shapes are
  10. * displayed until the ESC or q key is pressed. The
  11. * number of geometry stacks and slices can be adjusted
  12. * using the + and - keys.
  13. */
  14.  
  15. #ifdef __APPLE__
  16. #include <GLUT/glut.h>
  17. #else
  18. #include <GL/glut.h>
  19. #endif
  20.  
  21. #include <stdlib.h>
  22. #include <math.h>
  23.  
  24. void drawTriangle(int R, int G, int B, float x1, float y1, float x2, float y2, float x3, float y3)
  25. {
  26. glBegin(GL_TRIANGLES);
  27. glColor3ub(R, G, B);
  28. glVertex2f(x1, y1);
  29. glColor3ub(G, B, R);
  30. glVertex2f(x2, y2);
  31. glColor3ub(B, R, G);
  32. glVertex2f(x3, y3);
  33. glEnd();
  34. }
  35.  
  36. void drawCircle(int points)
  37. {
  38. glBegin(GL_LINE_LOOP);
  39. //set the color in 3 float number (red, green, blue)
  40. glColor3f(0.0, 1.0, 0.0);
  41.  
  42. float angle, x, y;
  43. for (int i = 0; i < points; i++){
  44. angle = 6.2832 * i / points;
  45. x = 0.5 * cos(angle);
  46. y = 0.5 * sin(angle);
  47. glVertex2f(x, y);
  48. }
  49. glEnd();
  50. }
  51. void square(float R, float G, float B){
  52. glColor3f(R,G,B);
  53. glBegin(GL_POLYGON);
  54. glVertex3f(0, 0, 0.5);
  55. glVertex3f(0.5, 0, 0.5);
  56. glVertex3f(0.5, 0.5, 0.5);
  57. glVertex3f(0, 0.5, 0.5);
  58. glEnd();
  59. }
  60. void cube(float size){
  61. glPushMatrix(); //save a copy of the current matrix
  62. glScalef(size,size,size);
  63. square(1, 0, 0); //red color side
  64. glPushMatrix();
  65. glRotatef(90, 0, 1, 0); //rotate by y
  66. square(0, 1, 0); //green color side
  67. glPopMatrix();
  68. glPushMatrix();
  69. glRotatef(-90, 1, 0, 0);
  70. square(0, 0, 1);
  71. glPopMatrix();
  72. glPushMatrix();
  73. glRotatef(180, 0, 1, 0);
  74. square(0, 1, 1);
  75. glPopMatrix();
  76. glPushMatrix();
  77. glRotatef(-90, 0, 1, 0);
  78. square(1, 0, 1);
  79. glPopMatrix();
  80. glPushMatrix();
  81. glRotatef(90, 1, 0, 0);
  82. square(1, 1, 0);
  83. glPopMatrix();
  84. glPopMatrix(); // restore matrix to its state before cube() was created.
  85. }
  86. void display(){
  87. //clear memory color buffer
  88. glClear(GL_COLOR_BUFFER_BIT);
  89. glLoadIdentity();
  90. //drawTriangle(66, 135, 245, -0.5, -0.5, 0.5, -0.5, 0, 0.5);
  91. //drawCircle(64);
  92. //drawTriangle(0, 0, 255, -1, -1, 0, 1, 1, -1);
  93. //glTranslatef(0.00005, 0.0, 0.0);
  94. /*Spinning ventilator static double x = 15;
  95. x = x + 0.15;
  96. glRotatef(x,0,0,1);
  97.  
  98.  
  99. glPushMatrix();
  100. drawTriangle(0, 0, 255, 0, 0, 0.5, 0.5, 0.5, 0);
  101. glPopMatrix();
  102.  
  103. glPushMatrix();
  104. drawTriangle(0, 0, 255, 0, 0, -0.5, -0.5, -0.5, 0);
  105. glPopMatrix();
  106.  
  107. glPushMatrix();
  108. drawTriangle(0, 0, 255, 0, 0, 0, -0.5, 0.5, -0.5);
  109. glPopMatrix();
  110.  
  111. glPushMatrix();
  112. drawTriangle(0, 0, 255, 0, 0, 0, 0.5, -0.5, 0.5);
  113. glPopMatrix();
  114. */
  115. glTranslated(0.1,0.1,0);
  116.  
  117. static double x = 15;
  118. x = x + 0.15;
  119. glRotatef(x,0,0,1);
  120.  
  121. square(0,1,1);
  122. glPushMatrix();
  123. drawTriangle(0,0,255,0,0.5,0.5,0.5,0.25,0.75);
  124.  
  125. /*drawTriangle(247, 128, 30,-0.5,0.5,0.5,1,0,0.5);
  126.  
  127. glPushMatrix();
  128. glTranslatef(0.03, 0, 0);
  129. glScalef(0.4,0.5,0.7);
  130. glRotatef(150,0,1,0);
  131. drawTriangle(64, 135, 255, 0.5,0.5,0.5,-0.5,-0.5,-0.5);
  132. glPopMatrix();
  133. */
  134. /*glPushMatrix();
  135. glTranslatef(0.00005, 0.0, 0.0);
  136. drawTriangle(0, 0, 255, -1, -1, 0, 1, 1, -1);
  137. glPopMatrix();*/
  138.  
  139. //switch
  140. //memory buffer
  141. glutSwapBuffers();
  142. }
  143. //reshape windows
  144. void reshape(int WIDTH, int HEIGHT){
  145. //sets viewport size from X to win width and from Y to win height
  146. glViewport(0, 0, WIDTH, HEIGHT);
  147. }
  148.  
  149. void onInit(){
  150. //glClearColor(R,G,B,A) sets windows background RGB color + alpha channel
  151. glClearColor(0.0, 0.0, 0.0, 1.0);
  152. }
  153.  
  154. int main(int argc, char **argv){
  155.  
  156. //glutInit is used to initialize the GLUT library
  157. glutInit(&argc, argv);
  158.  
  159. // glutInitDisplayMode sets the initial display modes
  160. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
  161. // glutInitWindowSize sets windows size in pixels (W, H)
  162. glutInitWindowSize(720, 720);
  163. // glutWindowsPosition sets windows position, from left down corner
  164. glutInitWindowPosition(100,100);
  165. // glutCreateWindows create windows and sets windows title
  166. glutCreateWindow ("My first OpenGL Windows");
  167.  
  168. onInit();
  169.  
  170. glutDisplayFunc(display);
  171. glutIdleFunc(display);
  172. glutReshapeFunc(reshape);
  173. glutMainLoop();
  174.  
  175. return 0;
  176. }
  177.  
Add Comment
Please, Sign In to add comment