Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<stdio.h>
- #include<stdlib.h>
- #include<math.h>
- #include <GL/freeglut.h>
- int ilosc;
- void wytnij(float x)
- {
- glColor3f(0.0f, 0.0f, 0.0f);
- glVertex2f(x/3, x/3);
- glVertex2f(x/3, -x/3);
- glVertex2f(-x/3, -x/3);
- glVertex2f(-x/3, x/3);
- }
- void rys(float x)
- {
- glColor3f(1.0f, 0.0f, 0.0f);
- glVertex2f(x, x);
- glColor3f(0.0f, 1.0f, 0.0f);
- glVertex2f(x, -x);
- glColor3f(0.0f, 0.0f, 1.0f);
- glVertex2f(-x, -x);
- glColor3f(1.0f, 1.0f, 0.0f);
- glVertex2f(-x, x);
- }
- void DrawScene(void);
- void InitOpenGL(void);
- void ReshapeWindow(int width, int height);
- int mainWindow;
- using namespace std;
- int main(int argc, char **argv)
- {
- cout<< "Podaj Ilosc kwadratow"<<endl;
- cin>> ilosc;
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
- glutInitWindowSize(1000 ,1000);
- glutInitWindowPosition(150,150);
- mainWindow = glutCreateWindow("Pierwsze Laboratorium");
- if(mainWindow == 0){
- puts("Nie mozna stworzyc okna!!!\nWyjscie z programu.\n");
- exit(-1);
- }
- glutSetWindow(mainWindow);
- glutDisplayFunc(DrawScene);
- glutReshapeFunc(ReshapeWindow);
- InitOpenGL();
- glutMainLoop();
- return(0);
- }
- void DrawScene(void)
- {
- glBegin(GL_QUADS);
- float x=90;
- rys(x);
- wytnij(x);
- float po=2*x/3;
- float s=2*x/9;
- for(int t =0; t<ilosc; t++)
- {
- for(double i=0; i<2*x; i=i+3*s)
- {
- for(double j=0; j<2*x; j=j+3*s)
- {
- glColor3f(0.0f, 0.0f, 0.0f);
- glVertex2f(-x+po/3+i, -x+po/3+j);
- glVertex2f(-x+po/3+i, -x+po/3+s+j);
- glVertex2f(-x+po/3+s+i, -x+po/3+s+j);
- glVertex2f(-x+po/3+s+i, -x+po/3+j);
- }
- }
- s/=3;
- po/=3;
- }
- glEnd();
- glFlush();
- }
- void InitOpenGL(void)
- {
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- }
- void ReshapeWindow(int width, int height)
- {
- int aspectRatio;
- if(height == 0) height = 1;
- aspectRatio = width / height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- if(width <= height)
- glOrtho(-100.0, 100.0, -100.0/aspectRatio, 100.0/aspectRatio, 1.0, -1.0);
- else
- glOrtho(-100.0*aspectRatio, 100.0*aspectRatio, -100.0, 100.0, 1.0, -1.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement