Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<windows.h>
- #include <GL/glut.h>
- #include <iostream>
- using namespace std;
- bool state = true;
- float x = 0.0, y = 100.0;
- void init(void)
- {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glMatrixMode(GL_PROJECTION);
- gluOrtho2D(0.0, 800.0, 0.0, 800.0);
- }
- void drawShapes(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- cout << x << " " << y << " " << int(state) << endl;
- if(state)
- {
- if(x < 700 || y < 700)
- {
- x += 0.1;
- y += 0.1;
- }
- else
- {
- state = false;
- }
- }
- else
- {
- if(x > 0 || y > 100)
- {
- x -= 0.1;
- y -= 0.1;
- }
- else
- {
- state = true;
- }
- }
- glColor3f(1.0, 1.0, 1.0);
- glBegin(GL_QUADS);
- glVertex2i(x, y);
- glVertex2i(x+100, y);
- glVertex2i(x+100, y-100);
- glVertex2i(x, y-100);
- glEnd();
- glColor3f(1.0, 0.0, 0.0);
- glBegin(GL_QUADS);
- glVertex2i(x, 200);
- glVertex2i(x+100, 200);
- glVertex2i(x+100, 100);
- glVertex2i(x, 100);
- glEnd();
- glColor3f(0.0, 0.0, 1.0);
- glBegin(GL_QUADS);
- glVertex2i(100, y);
- glVertex2i(200, y);
- glVertex2i(200, y-100);
- glVertex2i(100, y-100);
- glEnd();
- glutPostRedisplay();
- glFlush();
- }
- int main(int argc, char* argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
- glutInitWindowPosition(1200, 100);
- glutInitWindowSize(900, 900);
- glutCreateWindow("Four Stars");
- init();
- glutDisplayFunc(drawShapes);
- glutMainLoop();
- return 0;
- }
- /* cout << x << endl;
- if(!state)
- {
- x += 0.1;
- if(x > 750)
- {
- state != state;
- }
- }
- else
- {
- x -= 0.1;
- if(x <= 1) state != state;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment