Tuesday, October 27, 2020

Drawing a Wireframe using OpenGL

 


// C program to demonstrate

// drawing a hard wire house

// OpenGL

#include<stdio.h>

#include<GL/glut.h>

#include<math.h>

#define pi 3.142857


// function to initialize

void myInit (void)

{

// making background color grey as first

// 3 arguments all are 0.4

glClearColor(0.4, 0.4, 0.4, 0.4);


// making picture color green (in RGB mode), as middle argument is 1.0

    glColor3f(0.0, 1.0, 0.0);


// breadth of picture boundary is 2 pixel

glPointSize(2.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();


// setting window dimension in X- and Y- direction

gluOrtho2D(0.0,200.0, 0.0,150.0);

}


void display (void)

{

glClear(GL_COLOR_BUFFER_BIT);


glBegin(GL_LINES);

//horizontal base of the house

glVertex2i(50,0);

glVertex2i(100,0);

//horizontal ceiling of the house

glVertex2i(50,50);

glVertex2i(100,50);

//left roof top

glVertex2i(50,50);

glVertex2i(75,100);

//right roof

glVertex2i(75,100);

glVertex2i(100,50);

//left wall

glVertex2i(50,0);

glVertex2i(50,50);

//right wall

glVertex2i(100,0);

glVertex2i(100,50);


//Door top

glVertex2i(65,40);

glVertex2i(85,40);

//Door left side

glVertex2i(65,40);

glVertex2i(65,0);

//Door right side

glVertex2i(85,40);

glVertex2i(85,0);

    //Roof Box top

    glVertex2i(65,65);

glVertex2i(85,65);

    //Roof Box bottom

    glVertex2i(65,55);

glVertex2i(85,55);

    //Roof Box left side

    glVertex2i(65,65);

glVertex2i(65,55);

    //Roof Box right side

    glVertex2i(85,65);

glVertex2i(85,55);

//Out Box bottom left

    glVertex2i(0,25);

glVertex2i(25,0);

//Out Box bottom right

    glVertex2i(50,25);

glVertex2i(25,0);

    //Out Box top left

    glVertex2i(25,50);

glVertex2i(0,25);

//Out Box top right

    glVertex2i(25,50);

glVertex2i(50,25);



glEnd();

glFlush();

}


int main(int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);


// giving window size in X- and Y- direction

glutInitWindowSize(800,600);

glutInitWindowPosition(0,0);


// Giving name to window

glutCreateWindow("Drawing a Hard wire House");

myInit();


glutDisplayFunc(display);

glutMainLoop();

}

Output:








No comments:

Post a Comment

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows