How to Draw Hut In Visual Studio Using OpenGL Computer Graphics

  •  Here is the code which draws a hut in Computer Graphics programming using OPenGl.

Hut

 

  • First Don’t forget to include library og OpenGL.
  • In display() function glflush() function is called so that all the drawing which is remained left in buffer is displayed to output.
  • OptionMenu() function is working as switch you can understand easily by reading the code.
  • glVertex() sets cursor to draw some thing it depends what you want to draw.
  • Else whole code is self explanatory you can understand it by going through it
  • If you have any query please comment and share your useful knowledge with us.

Code :

 

#include <GL/glut.h>

void display()
{
glFlush();
}

void OptionsMenu (GLint selectedOpt)
{
switch (selectedOpt)
{
case 1:
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
break;

case 2:
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glEnd();
glFlush();
break;

case 3:
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.45, -0.5);
glVertex2f(-0.45, 0.5);
glVertex2f(-0.5, 0.5);
glEnd();
glBegin(GL_QUADS);
glVertex2f(-0.5, -0.5);
glVertex2f(0.5,-0.5);
glVertex2f(0.5, -0.45);
glVertex2f(-0.5, -0.45);
glBegin(GL_QUADS);
glVertex2f(0.45,-0.5);
glVertex2f(0.45,0.5);
glVertex2f(0.5,0.5);
glVertex2f(0.5,-0.5);
glEnd();
glBegin(GL_QUADS);
glVertex2f(0,0.9);
glVertex2f(0.05,0.85);
glVertex2f(-0.45,0.45);
glVertex2f(-0.5,0.5);
glEnd();
glBegin(GL_QUADS);
glVertex2f(0,0.9);
glVertex2f(-0.05,0.85);
glVertex2f(0.45,0.45);
glVertex2f(0.5,0.5);
glEnd();
glBegin(GL_QUADS);
glVertex2f(-0.3,0.8);
glVertex2f(-0.35,0.8);
glVertex2f(-0.35,0.6);
glVertex2f(-0.3,0.65);
glEnd();
glBegin(GL_QUADS);
glVertex2f(0,0.2);
glVertex2f(0.3,0.2);
glVertex2f(0.3,0.5);
glVertex2f(0,0.5);
glEnd();
glBegin(GL_QUADS);
glVertex2f(0,0);
glVertex2f(-0.3,0);
glVertex2f(-0.3,-0.5);
glVertex2f(0,-0.5);
glEnd();
glFlush();
break;
}
default:
break;
}

}
void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glColor3f(1.0, 1.0, 1.0);
}
void main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow(“Task 1”);
glutDisplayFunc(display);
glutCreateMenu (OptionsMenu);
glutAddMenuEntry(“Polygon “,1);
glutAddMenuEntry(“Line “,2);
glutAddMenuEntry(“Draw House”,3);
glutAttachMenu (GLUT_RIGHT_BUTTON);
init();
glutMainLoop();
}

Advertisement

8 Responses

    • ammadkhan

      The foreground of a composition is the visual plane that appears closest to the viewer, while the background is the plane in a composition percieved furthest from the viewer.

      Reply
    • ammadkhan

      this is very detailed topic you can’t understand this by one line definition if you are really interested in this then you have to concern computer graphic book.

      Reply
  1. patel

    can u give me code for titanic plzzzzz its realy important for me and i get error on it plzz send me code on my email id..as soon as possible plzzz send me

    Reply

Leave a Reply