Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. #include <iostream>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<math.h>
  5.  
  6. #include <GL/freeglut.h>
  7. int ilosc;
  8. void wytnij(float x)
  9. {
  10.  
  11. glColor3f(0.0f, 0.0f, 0.0f);
  12. glVertex2f(x/3, x/3);
  13. glVertex2f(x/3, -x/3);
  14. glVertex2f(-x/3, -x/3);
  15. glVertex2f(-x/3, x/3);
  16.  
  17.  
  18. }
  19. void rys(float x)
  20. {
  21. glColor3f(1.0f, 0.0f, 0.0f);
  22. glVertex2f(x, x);
  23. glColor3f(0.0f, 1.0f, 0.0f);
  24. glVertex2f(x, -x);
  25. glColor3f(0.0f, 0.0f, 1.0f);
  26. glVertex2f(-x, -x);
  27. glColor3f(1.0f, 1.0f, 0.0f);
  28. glVertex2f(-x, x);
  29.  
  30.  
  31. }
  32.  
  33. void DrawScene(void);
  34.  
  35. void InitOpenGL(void);
  36.  
  37. void ReshapeWindow(int width, int height);
  38.  
  39. int mainWindow;
  40. using namespace std;
  41. int main(int argc, char **argv)
  42. {
  43. cout<< "Podaj Ilosc kwadratow"<<endl;
  44. cin>> ilosc;
  45.  
  46. glutInit(&argc, argv);
  47. glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
  48. glutInitWindowSize(1000 ,1000);
  49. glutInitWindowPosition(150,150);
  50. mainWindow = glutCreateWindow("Pierwsze Laboratorium");
  51.  
  52. if(mainWindow == 0){
  53. puts("Nie mozna stworzyc okna!!!\nWyjscie z programu.\n");
  54. exit(-1);
  55. }
  56.  
  57. glutSetWindow(mainWindow);
  58.  
  59. glutDisplayFunc(DrawScene);
  60. glutReshapeFunc(ReshapeWindow);
  61.  
  62.  
  63. InitOpenGL();
  64.  
  65. glutMainLoop();
  66.  
  67. return(0);
  68. }
  69.  
  70. void DrawScene(void)
  71. {
  72.  
  73.  
  74. glBegin(GL_QUADS);
  75. float x=90;
  76. rys(x);
  77. wytnij(x);
  78. float po=2*x/3;
  79. float s=2*x/9;
  80. for(int t =0; t<ilosc; t++)
  81. {
  82. for(double i=0; i<2*x; i=i+3*s)
  83. {
  84. for(double j=0; j<2*x; j=j+3*s)
  85. {
  86. glColor3f(0.0f, 0.0f, 0.0f);
  87. glVertex2f(-x+po/3+i, -x+po/3+j);
  88.  
  89. glVertex2f(-x+po/3+i, -x+po/3+s+j);
  90.  
  91. glVertex2f(-x+po/3+s+i, -x+po/3+s+j);
  92.  
  93. glVertex2f(-x+po/3+s+i, -x+po/3+j);
  94. }
  95. }
  96. s/=3;
  97. po/=3;
  98. }
  99. glEnd();
  100. glFlush();
  101. }
  102.  
  103. void InitOpenGL(void)
  104. {
  105.  
  106. glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  107. }
  108.  
  109. void ReshapeWindow(int width, int height)
  110. {
  111. int aspectRatio;
  112. if(height == 0) height = 1;
  113. aspectRatio = width / height;
  114. glViewport(0, 0, width, height);
  115. glMatrixMode(GL_PROJECTION);
  116. glLoadIdentity();
  117. if(width <= height)
  118. glOrtho(-100.0, 100.0, -100.0/aspectRatio, 100.0/aspectRatio, 1.0, -1.0);
  119. else
  120. glOrtho(-100.0*aspectRatio, 100.0*aspectRatio, -100.0, 100.0, 1.0, -1.0);
  121. glMatrixMode(GL_MODELVIEW);
  122. glLoadIdentity();
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement