// firstGLproject.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include void displayStuffFirst(); void displayStuff(); void translateStuff(); void init(); void drawButton(); void handleButton(int button, int state, int x, int y); void drawSun(); void drawHouse(); const int Width = 720; const int Height=600; static float PI = 3.14159; static float RAD =3; static float INC = (PI/90); static GLfloat deltaz = .001; static GLfloat deltax= 0.0; static GLfloat deltay =0.0; void main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB| GLUT_MULTISAMPLE | GLUT_DEPTH); glutInitWindowSize(Width,Height); glutInitWindowPosition(0,0); glutCreateWindow("sun set"); glutDisplayFunc(displayStuffFirst); glutMouseFunc(handleButton); init(); glutMainLoop(); return; } void drawButton() { //glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glColor3f(1,0,0); glVertex2f(-10,-10); glColor3f(1,0,0); glVertex2f(-10,-8); glColor3f(1,0,0); glVertex2f(-8,-8); glColor3f(1,0,0); glVertex2f(-8,-10); glEnd(); } //works void displayStuff() { float theta; glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); for(theta =0.0; theta <=2*PI; theta+=INC) { glVertex2f(deltax +RAD*cos(theta), 8 +RAD*sin(theta)); glColor3f(1,1,0); } glEnd(); return; } void drawSun() { float theta; //sun glBegin(GL_POLYGON); for(theta =0.0; theta <=2*PI; theta+=INC) { glVertex2f(-7 +RAD*cos(theta), 9 +RAD*sin(theta)); glColor3f(1,1,0); } glEnd(); }//works void drawHouse() { // grass glBegin(GL_POLYGON); glColor3f(0.05,0.52,0.03); glVertex2f(12,2); glColor3f(0.05,0.52,0.03); glVertex2f(-10,2); glColor3f(0.19,0.32,0.03); glVertex2f(-10,-10); glColor3f(0.19,0.32,0.03); glVertex2f(12,-10); glEnd(); // path form door glBegin(GL_POLYGON); glColor3f(0.64,0.63,0.52); glVertex2f(-0.5,-3); glColor3f(0.64,0.63,0.52); glVertex2f(0.5,-3); glColor3f(0.64,0.63,0.52); glVertex2f(-2,-10); glColor3f(0.64,0.63,0.52); glVertex2f(-5,-10); glEnd(); //house glBegin(GL_POLYGON); glColor3f(0.5,0.47,0.43); glVertex2f(-3,-3); glColor3f(0.5,0.47,0.43); glVertex2f(-3,3); glColor3f(0.5,0.47,0.43); glVertex2f(3,3); glColor3f(0.3,0.3,0.3); glVertex2f(3,-3); glEnd(); //house door glBegin(GL_POLYGON); glColor3f(1,0.01,0.01); glVertex2f(-0.5,-1); glColor3f(1,0.01,0.01); glVertex2f(0.5,-1); glColor3f(1,0.01,0.01); glVertex2f(0.5,-3); glColor3f(0.78,0,0); glVertex2f(-0.5,-3); glEnd(); //window bottom left glBegin(GL_POLYGON); glColor3f(0.17,0.68,0.87); glVertex2f(-2,-2); glColor3f(0.17,0.68,0.87); glVertex2f(-2,-1); glColor3f(0.17,0.68,0.87); glVertex2f(-1,-1); glColor3f(0.17,0.38,0.87); glVertex2f(-1,-2); glEnd(); //window bottom right glBegin(GL_POLYGON); glColor3f(0.17,0.68,0.87); glVertex2f(2,-1); glColor3f(0.17,0.68,0.87); glVertex2f(1,-1); glColor3f(0.17,0.68,0.87); glVertex2f(1,-2); glColor3f(0.17,0.38,0.87); glVertex2f(2,-2); glEnd(); //window top right glBegin(GL_POLYGON); glColor3f(0.17,0.68,0.87); glVertex2f(1,1); glColor3f(0.17,0.68,0.87); glVertex2f(1,2); glColor3f(0.17,0.68,0.87); glVertex2f(2,2); glColor3f(0.17,0.38,0.87); glVertex2f(2,1); glEnd(); //window top left glBegin(GL_POLYGON); glColor3f(0.17,0.68,0.87); glVertex2f(-1,2); glColor3f(0.17,0.68,0.87); glVertex2f(-2,2); glColor3f(0.17,0.68,0.87); glVertex2f(-2,1); glColor3f(0.17,0.38,0.87); glVertex2f(-1,1); glEnd(); // seagull 1 glBegin(GL_LINES); glVertex2f(-3.5,6.5); glVertex2f(-3,6); glEnd(); glBegin(GL_LINES); glVertex2f(-3,6); glVertex2f(-2.5,6.5); glEnd(); // seagull 2 glBegin(GL_LINES); glVertex2f(-4.5,7.5); glVertex2f(-4,7); glEnd(); glBegin(GL_LINES); glVertex2f(-4,7); glVertex2f(-3.5,7.5); glEnd(); //house roof glBegin(GL_POLYGON); glColor3f(1,0.01,0.01); glVertex2f(3,3); glColor3f(1,0.01,0.01); glVertex2f(0,6); glColor3f(1,0.01,0.01); glVertex2f(-3,3); glEnd(); //3d effect house roof glBegin(GL_POLYGON); glColor3f(0.78,0,0); glVertex2f(3,3); glColor3f(0.69,0.08,0.08); glVertex2f(8,7); glColor3f(0.78,0,0); glVertex2f(5,10); glColor3f(1,0.01,0.01); glVertex2f(0,6); glEnd(); //house chiminy shadow glBegin(GL_POLYGON); glColor3f(1,0.01,0.01); glVertex2f(2,3); glColor3f(1,0.01,0.01); glVertex2f(3,3); glColor3f(0.1,0,0); glVertex2f(3,6); glColor3f(1,0.01,0.01); glVertex2f(2,6); glEnd(); //house chiminy glBegin(GL_POLYGON); glColor3f(1,0.01,0.01); glVertex2f(2,3); glColor3f(1,0.01,0.01); glVertex2f(3,3); glColor3f(1,0.01,0.01); glVertex2f(3,6); glColor3f(1,0.01,0.01); glVertex2f(2,6); glEnd(); //house chiminy 3d effect1 glBegin(GL_POLYGON); glColor3f(1,0.01,0.01); glVertex2f(3,3); glColor3f(0.5,0.01,0.01); glVertex2f(3.5,3.5); glColor3f(0.5,0.01,0.01); glVertex2f(3.5,6.5); glColor3f(1,0.01,0.01); glVertex2f(3,6); glEnd(); //house chiminy 3d effect2 glBegin(GL_POLYGON); glColor3f(0,0,0); glVertex2f(2,6); glColor3f(0,0,0); glVertex2f(3,6); glColor3f(0,0,0); glVertex2f(3.5,6.5); glColor3f(0,0,0); glVertex2f(2.5,6.5); glEnd(); //garage glBegin(GL_POLYGON); glColor3f(0.5,0.47,0.43); glVertex2f(3,-3); glColor3f(0.5,0.47,0.43); glVertex2f(3,1); glColor3f(0.5,0.47,0.43); glVertex2f(7,1); glColor3f(0.3,0.3,0.3); glVertex2f(7,-3); glEnd(); //garage door glBegin(GL_POLYGON); glColor3f(0.64,0.63,0.52); glVertex2f(3.5,0.5); glColor3f(0.64,0.63,0.52); glVertex2f(6.5,0.5); glColor3f(0.53,0.47,0.38); glVertex2f(6.5,-3); glColor3f(0.64,0.63,0.52); glVertex2f(3.5,-3); glEnd(); //path to garage door glBegin(GL_POLYGON); glColor3f(0,0,0); glVertex2f(6.5,-3); glColor3f(0,0,0); glVertex2f(3.5,-3); glColor3f(0,0,0); glVertex2f(2,-10); glColor3f(0,0,0); glVertex2f(6,-10); glEnd(); //roof garage glBegin(GL_POLYGON); glColor3f(1,0.01,0.01); glVertex2f(3,3); glColor3f(1,0.01,0.01); glVertex2f(3,1); glColor3f(1,0.01,0.01); glVertex2f(7,1); glEnd(); //3d effect garage roof glBegin(GL_POLYGON); glColor3f(1,0.01,0.01);; glVertex2f(3,3); glColor3f(0.69,0.08,0.08); glVertex2f(7,1); glColor3f(0.78,0,0); glVertex2f(11,5); glColor3f(0.69,0.08,0.08); glVertex2f(8,7); glEnd(); //3d effect garage wall glBegin(GL_POLYGON); glColor3f(0.3,0.3,0.3); glVertex2f(11,5); glColor3f(0.5,0.47,0.43); glVertex2f(7,1); glColor3f(0.3,0.3,0.3); glVertex2f(7,-3); glColor3f(0.4,0.4,0.4); glVertex2f(11,2); glEnd(); } //works void displayStuffFirst() { glClear(GL_COLOR_BUFFER_BIT); drawSun(); drawHouse(); drawButton(); glutSwapBuffers(); glFlush(); return; } void handleButton(int button,int state, int x, int y) { if(button == GLUT_LEFT_BUTTON) { if (x >0 && x <= 65 && y> 545 && y <= 600) { if (state == GLUT_DOWN) { glutIdleFunc(translateStuff); } if (state == GLUT_UP) { glutIdleFunc(NULL); } } } glutSwapBuffers(); } //works void translateStuff() { static int goingright = 0; static int goingdown = 0; glClear(GL_COLOR_BUFFER_BIT); if (goingright == 1) { deltax+= .05; if (deltax <= -10) { goingright = 0; } } if (goingright == 0) { deltax -= .05; if (deltax >= 0) { goingright = 1; } } glPushMatrix(); displayStuff(); glTranslatef(deltax, deltay, 0.0); glPopMatrix(); drawHouse(); drawButton(); glutSwapBuffers(); } void init() { glClearColor(0.33,0.95,0.94,0.0); glColor3f(1.0,1.0,1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-10.0,12.0,-10.0,12.0); return; }