/* Dackral Phillips CSE 540 Lab #1 This program draws several Open GL primitives to the screen in a variety of colors In particular, a field of grass is composed of 1 QUAD primitive 4 Mountains are composed of 1 TRIANGLE primitive apiece And a log cabin is composed of 3 QUAD primitives, a TRIANGLE PRIMITIVE and 6 LINE primitives*/ #include #include #include void init() { glClearColor(0.8f, 0.8f, 1.0f, 1.0f); glShadeModel(GL_SMOOTH); } void reshape(GLsizei w, GLsizei h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 250.0,0.0, 250.0,-1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void display() { glClear (GL_COLOR_BUFFER_BIT); /* Draw a box of grass */ glBegin(GL_QUADS); glColor3f(0.0, 1.0, 0.0); glVertex2f(250.0, 0.0); glColor3f(0.0, 0.9, 0.0); glVertex2f(250.0, 50.0); glColor3f(0.0, 0.8, 0.0); glVertex2f(0.0, 50.0); glColor3f(0.0, 0.7, 0.0); glVertex2f(0.0, 0.0); glEnd(); /* An attempt at a few snow covered mountains */ glBegin(GL_TRIANGLES); glColor3f(0.0, 0.0, 0.6); glVertex2f(250.0, 50.0); glColor3f(1.0, 1.0, 1.0); glVertex2f(200.0, 150.0); glColor3f(0.0, 0.0, 0.5); glVertex2f(150.0, 50.0); glBegin(GL_TRIANGLES); glColor3f(0.0, 0.0, 0.5); glVertex2f(200.0, 50.0); glColor3f(1.0, 1.0, 1.0); glVertex2f(150.0, 150.0); glColor3f(0.0, 0.0, 0.5); glVertex2f(100.0, 50.0); glColor3f(0.0, 0.0, 0.7); glVertex2f(150.0, 50.0); glColor3f(1.0, 1.0, 1.0); glVertex2f(100.0, 150.0); glColor3f(0.0, 0.0, 0.5); glVertex2f(50.0, 50.0); glColor3f(0.0, 0.0, 0.5); glVertex2f(100.0, 50.0); glColor3f(1.0, 1.0, 1.0); glVertex2f(50.0, 150.0); glColor3f(0.0, 0.0, 0.5); glVertex2f(0.0, 50.0); glEnd(); /* A make shift log cabin */ glBegin(GL_QUADS); glColor3f(0.4, 0.4, 0.0); glVertex2f(175.0, 15.0); glVertex2f(175.0, 65.0); glVertex2f(75.0, 65.0); glVertex2f(75.0, 15.0); glColor3f(0.2, 0.2, 0.0); glVertex2f(135.0, 15.0); glVertex2f(135.0, 45.0); glVertex2f(115.0, 45.0); glVertex2f(115.0, 15.0); glVertex2f(165.0, 65.0); glVertex2f(165.0, 105.0); glVertex2f(155.0, 105.0); glVertex2f(155.0, 65.0); glEnd(); glBegin(GL_TRIANGLES); glColor3f(0.2, 0.2, 0.0); glVertex2f(190.0, 65.0); glVertex2f(125.0, 105.0); glVertex2f(60.0, 65.0); glEnd(); glBegin(GL_LINES); glColor3f(0.0, 0.0, 0.0); glVertex2f(174, 25); glVertex2f(135, 25); glVertex2f(174, 35); glVertex2f(135, 35); glVertex2f(174, 45); glVertex2f(75, 45); glVertex2f(174, 55); glVertex2f(75, 55); glVertex2f(114, 35); glVertex2f(75, 35); glVertex2f(114, 25); glVertex2f(75, 25); glEnd(); glutSwapBuffers(); glFlush(); } void keyboard(unsigned char key, int x, int y) { switch(key) { case 27: exit(0); break; } } void main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(50,50); glutInitWindowSize(500,500); glutCreateWindow("CSE 540 Lab #1"); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); }