0% found this document useful (0 votes)
35 views

Report House Using GLUT PDF

This document describes a project to draw a 2D house using OpenGL and GLUT. The house has a wall, roof, and door, each drawn with different algorithms - Bresenham's line algorithm for the wall and door, and digital differential algorithm for the roof. The source code implements these algorithms to draw the individual components of the house with different colors on a white background. Screenshots show the output of the simple GLUT program that renders the 2D house design with no animation.

Uploaded by

Gourab Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Report House Using GLUT PDF

This document describes a project to draw a 2D house using OpenGL and GLUT. The house has a wall, roof, and door, each drawn with different algorithms - Bresenham's line algorithm for the wall and door, and digital differential algorithm for the roof. The source code implements these algorithms to draw the individual components of the house with different colors on a white background. Screenshots show the output of the simple GLUT program that renders the 2D house design with no animation.

Uploaded by

Gourab Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

House using GLUT

A Project
Submitted to the Department of Computer Science & Engineering Bangladesh University of
Business & Technology (BUBT), Dhaka in partial fulfillment of the requirement for the Course of

Computer Graphics Lab


CSE 342
SEMESTER : 2020-2021 Fall

Submitted By
Satyajit Sarker
ID – 17182103157
Section – 4, Intake – 38
B. Sc. Engineering in CSE

Submitted To
Sudipto Chaki
Lecturer
Department of CSE
Bangladesh University of Business & Technology

Bangladesh University of Business & Technology (BUBT)


RUPNAGAR, MIRPUR-2, DHAKA-1216, BANGLADESH
2021 March
Index
Topic Page

Introduction 1

Short Description of the Project 1

Short Description of Used Algorithm 1

Source Code 1

Screenshot of Project Output 6

Conclusion 6
Page 1
Introduction

Rasterisation or rasterization is the task of taking an image described in vector graphics format
(shape) and convert it into raster image (pixel or dots) for output on a video display or printer, or
storage in a bitmap format. It is also know as scan conversion. In digital image processing, a pixel or
pel or picture element is the smallest addressable element in an image or display device. On a
display, pixel is arranged in vertical and horizontal way known as raster.

OpenGL Utility Toolkit (GLUT) is an OpenGL toolkit to draw OpenGL figures in C++. OpenGL or Open
Graphics Library is cross platform application platform interface (API) for rendering 2D and 3D
vector graphics.

Short Description of Project

This is a project to make simple GLUT program using various algorithm. The house has a wall, a
roof and a door, which are made of dots to form lines. This is a 2D design with no animation. The
wall, roof and door line have individual colour. The wall made of 4 points, door has 3 points and
the roof also has three points. The wall and door uses Bresenham Line Algorithm to draw line and
the roof uses Digital Differential Algorithm (DDA) to draw line. It also use glcolor3f() to colour the
individual lines. It also has white background.

Short Description of used Algorithm

As stated in previous paragraph, the roof use Digital Differential Algorithm (DDA). It is the simplest
line drawing algorithm. It uses straight line equation, y=mx+c, which is the value of slop ; to
calculate the parameter of the algorithm. This algorithm uses floating point operation and
rounding operation which is very expensive to calculate on processor. Though DDA is the simplest
line drawing algorithm, it is not very efficient.

The wall and the door uses Bresenham Line Algorithm. It works with slop value of 0<m<1 and it
draws from left to right. If value of slop m>1, then value of x and y is interchanges. This algorithm is
a fast incremental algorithm and it only uses integer calculation. As it uses integer calculation and
no round off operation, it is fast. And unlike DDA, Bresenham Line Algorithm is implementable on
hardware.

Source Code
#include<windows.h>
#include<bits/stdc++.h>
#include<GL/glut.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

int xx[4],yy[4],xx2[4],yy2[4];
Page 2
float ax[3],ay[3],bx[3],by[3];
int cx[3],cy[3],cx2[3],cy2[3];

void print_wall(int x,int y)


{
glBegin(GL_POINTS);
glColor3f(1.0,-1.0,-1.0);
glVertex2i(x,y);
glEnd();
}

void print_roof(int x,int y)


{
glBegin(GL_POINTS);
glColor3f(-1.0,-1.0,1.0);
glVertex2i(x,y);
glEnd();
}

void print_door(int x,int y)


{
glBegin(GL_POINTS);
glColor3f(-1.0,1.0,-1.0);
glVertex2i(x,y);
glEnd();
}

void Wall_point(int x1,int y1,int x2,int y2)


{
int dx,dy,s,vx,vy,endd,p0;
dx=abs(x2-x1);
dy=abs(y2-y1);
p0=2*dy-dx;
vx=x1,vy=y1;
if(x1!=x2){
if(x1>x2){
vx=x2;
vy=y2;
endd=x1;
}
else{
vx=x1;
vy=y2;
endd=x2;
}
print_wall(vx,vy);

while(vx<endd){
vx++;
if(p0<0){
Page 3
p0+=2*dy;
}
else{
vy++;
p0=p0+2*dy-2*dx;
}
print_wall(vx,vy);
}
}
else{
for(int i=min(y1,y2);i<=max(y1,y2);i++){
print_wall(vx,i);
}
}
glFlush();
}

void Roof_point(float x1,float y1,float x2,float y2)


{
float dx,dy,m,x0,y0;
dx=x2-x1;
dy=y2-y1;
m=dy/dx;
if(m<1){
y0=y1;
for(int i=x1;i<=x2;i++){
y0=y0+m;
print_roof(i,round(y0));
}
}
else{
x0=x1;
for(int i=y1;i<=y2;i++){
x0=x0+1/m;
print_roof(round(x0),i);
}
}
glFlush();
}

void Door_point(int x1,int y1,int x2,int y2)


{
int dx,dy,s,vx,vy,endd,p0;
dx=abs(x2-x1);
dy=abs(y2-y1);
p0=2*dy-dx;
vx=x1,vy=y1;
if(x1!=x2){
if(x1>x2){
vx=x2;
Page 4
vy=y2;
endd=x1;
}
else{
vx=x1;
vy=y2;
endd=x2;
}
print_door(vx,vy);

while(vx<endd){
vx++;
if(p0<0){
p0+=2*dy;
}
else{
vy++;
p0=p0+2*dy-2*dx;
}
print_door(vx,vy);
}
}
else{
for(int i=min(y1,y2);i<=max(y1,y2);i++){
print_door(vx,i);
}
}
glFlush();
}
void display ()
{
Wall_point(xx[0],yy[0],xx2[0],yy2[0]);
Wall_point(xx[1],yy[1],xx2[1],yy2[1]);
Wall_point(xx[2],yy[2],xx2[2],yy2[2]);
Wall_point(xx[3],yy[3],xx2[3],yy2[3]);

Roof_point(ax[0],ay[0],bx[0],by[0]);
Roof_point(ax[1],ay[1],bx[1],by[1]);
Roof_point(ax[2],ay[2],bx[2],by[2]);

Door_point(cx[0],cy[0],cx2[0],cy2[0]);
Door_point(cx[1],cy[1],cx2[1],cy2[1]);
Door_point(cx[2],cy[2],cx2[2],cy2[2]);
}

void init(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
Page 5
gluOrtho2D(-500,500,-500,500);
}

int main (int argc, char **argv)


{
xx[0]=20,yy[0]=0,xx2[0]=400,yy2[0]=0;
xx[1]=20,yy[1]=0,xx2[1]=20,yy2[1]=-260;
xx[2]=20,yy[2]=-260,xx2[2]=400,yy2[2]=-260;
xx[3]=400,yy[3]=-260,xx2[3]=400,yy2[3]=0;

ax[0]=0,ay[0]=0,bx[0]=420,by[0]=0;
ax[1]=0,ay[1]=0,bx[1]=210,by[1]=160;
ax[2]=210,ay[2]=160,bx[2]=420,by[2]=0;

cx[0]=160,cy[0]=-260,cx2[0]=160,cy2[0]=-160;
cx[1]=160,cy[1]=-160,cx2[1]=260,cy2[1]=-160;
cx[2]=260,cy[2]=-160,cx2[2]=260,cy2[2]=-260;

glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow(" House ");
init();
glutDisplayFunc(display);
glutMainLoop();
}
Page 6
Screenshot of Project Output

Conclusion

House using GLUT is very simple project. It has a lot of room for improvement, 3D design and
adding animation. But currently this is what I am capable of doing. So this is my GLUT project.

You might also like