Report House Using GLUT PDF
Report House Using GLUT PDF
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
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
Introduction 1
Source Code 1
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.
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.
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];
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();
}
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);
}
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.