Draw a house by opengl (c++)
Draw a house using OpenGL and glut by c++ programming
#include <GL/gl.h>
#include <GL/glut.h>
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 0.3, 0.9);
glBegin(GL_POLYGON);
glVertex2d (0, 0);
glVertex2d (60, 0);
glVertex2d (60, 12);
glVertex2d (0, 12);
glEnd();
glColor3f (0.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex2d (0, 40);
glVertex2d (60, 40);
glVertex2d (60, 60);
glVertex2d (0, 60);
glEnd();
glColor3f (0.1, 0.7, 0.1);
glBegin(GL_POLYGON);
glVertex2d (0, 40);
glVertex2d (60, 40);
glVertex2d (60, 45);
glVertex2d (55, 42);
glVertex2d (0, 45);
glEnd();
glColor3f (0.0, 0.8, 0.2);
glBegin(GL_POLYGON);
glVertex2d (0, 40);
glVertex2d (60, 40);
glVertex2d (60, 10);
glVertex2d (0, 10);
glEnd();
glColor3f (0.4, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex2d (0, 10);
glVertex2d (60, 10);
glVertex2d (60, 15);
glVertex2d (0, 15);
glEnd();
glColor3f (0.4, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex2d (15, 15);
glVertex2d (19, 15);
glVertex2d (22, 20);
glVertex2d (19, 20);
glEnd();
glColor3f (0.4, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex2d (45, 15);
glVertex2d (49, 15);
glVertex2d (52, 20);
glVertex2d (49, 20);
glEnd();
glColor3f (9.0, 0.7, 0.0);
glBegin(GL_TRIANGLES);
glVertex2d (2, 20);
glVertex2d (8, 20);
glVertex2d (5, 32);
glEnd();
glColor3f (0.3, 0.3, 0.0);
glBegin(GL_POLYGON);
glVertex2d (4.8, 19.0);
glVertex2d (5.2, 19.0);
glVertex2d (5.2, 20);
glVertex2d (4.8, 20);
glEnd();
glColor3f (0.8, 0.8, 0.8);
glBegin(GL_POLYGON);
glVertex2d (10, 22);
glVertex2d (15, 20);
glVertex2d (15, 30);
glVertex2d (10, 32);
glEnd();
glColor3f (0.0, 0.2, 0.9);
glBegin(GL_TRIANGLES);
glVertex2d (9, 32);
glVertex2d (15, 30);
glVertex2d (13, 35);
glEnd();
glColor3f (0.0, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex2d (11, 24.5);
glVertex2d (13, 23.5);
glVertex2d (13, 27.5);
glVertex2d (11, 28.5);
glEnd();
glColor3f (0.7, 0.7, 0.7);
glBegin(GL_POLYGON);
glVertex2d (15, 20);
glVertex2d (25, 20);
glVertex2d (25, 30);
glVertex2d (15, 30);
glEnd();
glColor3f (0.0, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex2d (19, 20);
glVertex2d (22, 20);
glVertex2d (22, 28);
glVertex2d (19, 28);
glEnd();
glColor3f (0.0, 0.0, 0.8);
glBegin(GL_TRIANGLES);
glVertex2d (15, 30);
glVertex2d (26, 30);
glVertex2d (20, 35);
glEnd();
glColor3f (0.0, 0.2, 0.9);
glBegin(GL_TRIANGLES);
glVertex2d (13, 35);
glVertex2d (15, 30);
glVertex2d (20, 35);
glEnd();
glColor3f (0.8, 0.8, 0.8);
glBegin(GL_POLYGON);
glVertex2d (40, 22);
glVertex2d (45, 20);
glVertex2d (45, 30);
glVertex2d (40, 32);
glEnd();
glColor3f (1.0, 0.0, 0.0);
glBegin(GL_TRIANGLES);
glVertex2d (39, 32);
glVertex2d (45, 30);
glVertex2d (43, 35);
glEnd();
glColor3f (0.1, 0.1, 0.1);
glBegin(GL_POLYGON);
glVertex2d (41, 24.5);
glVertex2d (43, 23.5);
glVertex2d (43, 27.5);
glVertex2d (41, 28.5);
glEnd();
glColor3f (0.7, 0.7, 0.7);
glBegin(GL_POLYGON);
glVertex2d (45, 20);
glVertex2d (55, 20);
glVertex2d (55, 30);
glVertex2d (45, 30);
glEnd();
glColor3f (0.1, 0.1, 0.1);
glBegin(GL_POLYGON);
glVertex2d (49, 20);
glVertex2d (52, 20);
glVertex2d (52, 28);
glVertex2d (49, 28);
glEnd();
glColor3f (0.5, 0.0, 0.0);
glBegin(GL_TRIANGLES);
glVertex2d (45, 30);
glVertex2d (56, 30);
glVertex2d (50, 35);
glEnd();
glColor3f (0.5, 0.0, 0.0);
glBegin(GL_TRIANGLES);
glVertex2d (43, 35);
glVertex2d (45, 30);
glVertex2d (50, 35);
glEnd();
glColor3f (0.5, 0.0, 0.1);
glBegin(GL_TRIANGLES);
glVertex2d (30, 20);
glVertex2d (36, 20);
glVertex2d (33, 25);
glEnd();
glColor3f (0.0, 0.6, 0.0);
glBegin(GL_POLYGON);
glVertex2d (34, 33);
glVertex2d (37, 30);
glVertex2d (37, 34);
glVertex2d (40, 37);
glVertex2d (39, 40);
glVertex2d (40, 43);
glVertex2d (36, 47);
glVertex2d (34, 51);
glVertex2d (31, 47);
glVertex2d (28, 45);
glVertex2d (26, 42);
glVertex2d (27, 36);
glVertex2d (29, 35);
glVertex2d (29, 31);
glVertex2d (30, 33);
glVertex2d (32, 33);
glVertex2d (34, 33);
glEnd();
glColor3f (0.5, 0.0, 0.1);
glBegin(GL_POLYGON);
glVertex2d (32, 23);
glVertex2d (34, 23);
glVertex2d (34, 36);
glVertex2d (32, 36);
glEnd();
glColor3f (0.5, 0.0, 0.1);
glBegin(GL_POLYGON);
glVertex2d (34, 35);
glVertex2d (37, 38);
glVertex2d (35, 40);
glVertex2d (33, 36);
glVertex2d (31, 42);
glVertex2d (30, 40);
glVertex2d (32, 35);
glEnd();
glFlush ();
}
void init (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 60, 0, 60);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (1200, 600);
glutInitWindowPosition (0, 0);
glutInitWindowPosition (0, 0);
glutCreateWindow (" Scenery ");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0;
No comments