In this post i am drawing a simple house in OpenGL. House is consist of some basic Triangles and rectangular shapes by using these i am going to make a simple House.

Download Source code

void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);

int y = 200;
glBegin(GL_LINE_LOOP);

glVertex2i(70, 10 + y ); // draw some points (don’t know how many)
glVertex2i(70, 130 + y);
glVertex2i(150, 130 + y);
glVertex2i(150, 10 + y);
glEnd();
glBegin(GL_LINE_LOOP);

glVertex2i(70, 130 + y); // draw some points (don’t know how many)
glVertex2i(110, 230 + y);
glVertex2i(150, 130 + y);

glEnd();
glBegin(GL_LINE_LOOP);

glVertex2i(150, 130 + y); // draw some points (don’t know how many)
glVertex2i(300, 130 + y);
glVertex2i(300, 10 + y);
glVertex2i(150, 10 + y);

glEnd();
glBegin(GL_LINE_LOOP);

glVertex2i(110, 230 + y); // draw some points (don’t know how many)
glVertex2i(300, 230 + y);
glVertex2i(300, 130 + y);
glVertex2i(70, 130 + y);

glEnd();
glBegin(GL_LINE_LOOP);

glVertex2i(180, 40 + y); // draw some points (don’t know how many)
glVertex2i(180, 100 + y);
glVertex2i(270, 100 + y);
glVertex2i(270, 40 + y);

glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(225, 100 + y);
glVertex2i(225, 40 + y);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(180, 70 + y);
glVertex2i(270, 70 + y);

glEnd();
glFlush();

}

First make different shapes , which are used later for making a whole house starting from any where just imagine and focus on your points where you’re going to draw and which shapes are joining.

int y=200;  i create a variable y that holds value 200.

and i add y to each vertex let say glVertex2i(0, 0 + y);

By adding Y i just move the point vertically upward  (traveling upward direction in Y-axis ). remember our screen is 480 Y pixels . so it just move the whole house upward 200 points.

Now there is a task for you add X variable to each vertex to move house horizontally .

There is nothing new in this post we used previous functions to draw this house if you want to learn these function read my previous posts.

Advertisements