Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<GL/gl.h>
- #include <GL/glut.h>
- using namespace std;
- float _move = 0.0f;
- void drawScene() {
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadIdentity(); //Reset the drawing perspective
- glMatrixMode(GL_MODELVIEW);
- glColor3d(1,0,0);
- glPushMatrix();
- glTranslatef(_move, 0.0f, 0.0f);
- glBegin(GL_QUADS);
- glVertex3f(-.80f, -0.1f, 0.0f);
- glVertex3f(-.30f, -0.1f, 0.0f);
- glVertex3f(-.10f, 0.2f, 0.0f);
- glVertex3f(-1.0f, 0.2f, 0.0f);
- glEnd();
- glPopMatrix();
- glColor3d(.87,0.749,0.38);
- glPushMatrix();
- glTranslatef(_move, 0.0f, 0.0f);
- glBegin(GL_QUADS);
- glVertex3f(-.50f, 0.2f, 0.0f);
- glVertex3f(-.40f, 0.2f, 0.0f);
- glVertex3f(-.40f, 0.4f, 0.0f);
- glVertex3f(-.50f, 0.4f, 0.0f);
- glEnd();
- glPopMatrix();
- glColor3d(.87,0.749,0.38);
- glPushMatrix();
- glTranslatef(_move, 0.0f, 0.0f);
- glBegin(GL_QUADS);
- glVertex3f(-.70f, 0.2f, 0.0f);
- glVertex3f(-.60f, 0.2f, 0.0f);
- glVertex3f(-.60f, 0.6f, 0.0f);
- glVertex3f(-.70f, 0.6f, 0.0f);
- glEnd();
- glPopMatrix();
- glColor3d(.87,0.749,0.38);
- glPushMatrix();
- glTranslatef(_move, 0.0f, 0.0f);
- glBegin(GL_QUADS);
- glVertex3f(-.30f, 0.2f, 0.0f);
- glVertex3f(-.20f, 0.2f, 0.0f);
- glVertex3f(-.20f, 0.3f, 0.0f);
- glVertex3f(-.30f, 0.3f, 0.0f);
- glEnd();
- glPopMatrix();
- glBegin(GL_POLYGON);
- glColor3f(0,0,1);
- glVertex2i(-1.0f,-1.0f);
- glVertex2i(1.0f,-1.0f);
- glVertex2i(1.0f,-.50f);
- glVertex2i(-1.0f,-.50f);
- glEnd();
- glPushMatrix();
- glColor3d(.894,.91,.93);
- glTranslatef(-0.45f+_move, .45, 0.0);
- glutSolidSphere(.01,50,50);
- glEnd();
- glPopMatrix();
- glPushMatrix();
- glColor3d(.894,.91,.93);
- glTranslatef(-0.48f+_move, .52, 0.0);
- glutSolidSphere(.015,50,50);
- glEnd();
- glPopMatrix();
- glPushMatrix();
- glColor3d(.894,.91,.93);
- glTranslatef(-0.51f+_move, .59, 0.0);
- glutSolidSphere(.02,50,50);
- glEnd();
- glPopMatrix();
- glPushMatrix();
- glColor3d(.894,.91,.93);
- glTranslatef(-0.65f+_move, .64, 0.0);
- glutSolidSphere(.01,50,50);
- glEnd();
- glPopMatrix();
- glPushMatrix();
- glColor3d(.894,.91,.93);
- glTranslatef(-0.68f+_move, .72, 0.0);
- glutSolidSphere(.015,50,50);
- glEnd();
- glPopMatrix();
- glPushMatrix();
- glColor3d(.894,.91,.93);
- glTranslatef(-0.7f+_move, .79, 0.0);
- glutSolidSphere(.02,50,50);
- glEnd();
- glPopMatrix();
- glPushMatrix();
- glColor3d(.894,.91,.93);
- glTranslatef(-0.25f+_move, .35, 0.0);
- glutSolidSphere(.01,50,50);
- glEnd();
- glPopMatrix();
- glPushMatrix();
- glColor3d(.894,.91,.93);
- glTranslatef(-0.28f+_move, .42, 0.0);
- glutSolidSphere(.015,50,50);
- glEnd();
- glPopMatrix();
- glPushMatrix();
- glColor3d(.894,.91,.93);
- glTranslatef(-0.31f+_move, .49, 0.0);
- glutSolidSphere(.02,50,50);
- glEnd();
- glPopMatrix();
- //glFlush(); //Works only on single buffer
- glutSwapBuffers();
- }
- void update(int value) {
- _move += .02;
- if(_move-1.3 > 1.0)
- {
- _move = -1.0;
- }
- glutPostRedisplay(); //Notify GLUT that the display has changed
- glutTimerFunc(20, update, 0); //Notify GLUT to call update again in 20 milliseconds
- }
- int main(int argc, char** argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(800, 800);
- glutCreateWindow("Transformation");
- glutDisplayFunc(drawScene);
- glutTimerFunc(20, update, 0); //Add a timer
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement