Computer Graphics
Computer Graphics
CHAPTER - 1
OpenGL was developed by Silicon Graphics Inc. (SGI) in 1992 and is widely used in CAD,
INTRODUCTION virtual reality, scientific visualization, information visualization and flight simulation. It is also
used in video games, where it competes with direct 3D on Microsoft Windows platforms.
COMPUTER GRAPHICS:
OpenGL provides a powerful but primitive set of rendering command, and all higher-level
Computer graphics is concerned with all aspects of producing pictures or images using drawing must be done in terms of these commands. There are several libraries that allow you to
computer. The field began humble almost 50 years ago, with the display of few lines on the cathode simplify your programming tasks, including the following:
ray tube (CRT) now, we can create images using computer that are indistinguishable from
photographs from the real objects. OpenGL Utility Library (GLU) contains several routines that use lower-level OpenGL
Today computers and computer-generated images touch many aspects of our daily life. commands to perform such tasks as setting up matrices for specific viewing orientations
Computer imagery is found on television, in newspapers, in weather reports, and during surgical and projections and rendering surfaces.
procedures. A well-constructed graph can present complex statistics in a form that is and other
presentation material. A range of tools and facilities are available to enable users to visualize their OpenGL Utility Toolkit (GLUT) is a window-system-independent toolkit, written by Mark
data, and computer graphics are used in many disciplines Kilgard, to hide the complexities of differing window APIs. Rather than using a different
Graphics is created using computers and generally, the representation and manipulation of library for each system we use available library called openly utility toolkit. It is used as
pictorial data by computer .the development of computer graphics has made computers easier to #include <glut.h>.
interact and better for understanding and interpreting many types of data. The phrase “computer
graphics” was coined in 1960 by William Fetter, a graphic designer for Boeing.
The graphics in openly provides a wide variety of built-in functions. The computer graphics
remains one of the most exciting and growing computer fields. It has become a common element
in user interface. Major applications of computer graphics are in Computational Biology,
Computational physics, Computer Aided Designing, Computer simulation, Digital art, Education,
Graphic Design, Video gaming, Virtual reality and Web designing….etc. 1.1 Aim:
Show a walk-in simulation through the campus of college. The campus is visualized in a
3D perspective view with keyboard and mouse inputs for navigating through the campus
down approach. OpenGL is a standard specification defining a cross-language, Cross-platform is transformation of objects. This projects involves the demonstration of some of the
transformation.A project using OpenGL to show a walk-in simulation through the campus of
API for writing applications that produce 2D and 3D computer graphics. The interface consists of
college.A project implemented using c and OpenGL in VisualStudio,aims at simulating the
over 250 different function calls which can be used to draw complex three dimensional scenes campus of the college. The campus portrayed is a sample of how the real campus looks however
details such as paint color and building dimensions couldn’t be accounted for.With help of textures Step 4: [Keyboard is used to interact with the user]
I have the football field . If „
“Mouse left” is pressed
Then
Input keys for the application: Drag left rotate & view towards left
If „
f-Move forward
“Mouse right” is pressed
b-Move backward Then
CHAPTER – 2 If,,
”u” key is pressed
DESIGN AND IMPLEMENTATION Then
2.1 ALGORITHM glutKeyboardFunc() function gets called
void gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top): Defines
2.3 OPENGL WITH DESCRIPTION a two-dimensional viewing rectangle in the plane.
Most of our application will be designed to access OpenGL directly through functions in
three libraries. Functions in the main GL (or OpenGL in windows) library have names that begin
void glutCreateWindow(char *title) : Creates a window on the display. The string title can be
with the letters gl and are stored in a library usually referred to as GL (or OpenGL in windows).
The second is the OpenGL Utility Library (GLU). This library uses only GL functions but used to label the window. The return value provides a reference to the window that can be used
contains code for creating common objects and simplifying viewing. All functions in GLU can be when there are multiple windows.
created from the core GL library but application programmers prefer not to write the code
repeatedly. The GLU library is available in all OpenGL implementations; functions in the GLU
library begin with letters glu. void glutInitDisplaymode(unsigned int mode) :Requests a display with the properties in mode.
This project makes extensive use of translations, rotations and scaling for creating Provides The value of mode is determined by the logical OR of options including the color
the description of the following functions. model(GLUT_RGB<GLUT_INDEX) and buffering (GLUT_SINGLE<GLUT_DOUBLE).
void glScalef(TYPE sx, TYPE sy, TYPE sz): Alters the current matrix by a scaling of (sx, sy,
sz). TYPE here is GLfloat. void glutInitWindowSize(int width,int heights) :Specifies the initial height and width of the
Here in the above considered example we use scaling to minimize the length of the curve at each window in pixels.
iteration. For this curve we use the scale factor to be 3 units because we substitute a line by 4 lines
in each iteration void glutInitWindowPosition(int x,int y) :Specifies the initial position of the top-left corner of
the window in pixels.
void glRotatef(TYPE angle, TYPE dx, TYPE dy, TYPE dz): Aalters the current matrix by a
rotation of angle degrees about the axis(dx, dy, dz). TYPE here is GLfloat. void glViewport(int x,int y,GLsizei width,GLsizei height): Specifies a width * height viewport
For a Koch curve we rotate by 60° about the z-axis. in pixels whose lower-left corner is at (x,y) measured from he origin of the window.
void glTranslatef(TYPE x, TYPE y, TYPE z): Alters the current matrix by a displacement of void glutMainLoop(): Cause the program to enter an event –processing loop.it should be the
(x, y, z). TYPE here is GLfloat. statement in main.
We need to translate to display the new position of the line from the old position and also to go
out to the beginning of the next side while drawing. void glutPostRedisplay() :Requests that the display callback be executed after the current
callback returns.
void glLoadIdentity(): Sets the current transformation matrix to an identity matrix.
void glPushMatrix(): Pushes to the matrix stack corresponding to the current matrix mode.
void glPopMatrix(): Pops from the matrix stack corresponding to the current matrix mode.
glPushMatrix(); glBegin(GL_QUADS);
glTranslatef(-70,0.1,20); glVertex3f(k,0,0.1);
glColor3f(0.5,0.5,0.5); glVertex3f(k,4,0.1);
glBegin(GL_QUADS); glVertex3f(k-2,4,0.1);
glVertex3f(0,0,0); glVertex3f(k-2,0,0.1);
glVertex3f(20,0,0); glEnd();
glVertex3f(20,0,-40); }
glVertex3f(0,0,-40); glPopMatrix();
glEnd(); glPushMatrix();
glColor3f(0,0,0); glTranslatef(-65,0.1,15);
for(k=2;k<18;k+=4) glColor3f(0,0,1);
{ glBegin(GL_QUADS);
glBegin(GL_QUADS); glVertex3f(0,0.2,0);
glVertex3f(k,0,-0.1); glVertex3f(10,0.2,0);
glVertex3f(k,4,-0.1); glVertex3f(10,0.2,-30);
glVertex3f(k+2,4,-0.1); glVertex3f(0,0.2,-30);
glVertex3f(k+2,0,-0.1); glEnd();
glEnd(); glColor3f(1,1,1);
} glBegin(GL_LINE_LOOP);
for(k=-2;k>-38;k-=6) glVertex3f(1,0.3,-1);
{ glVertex3f(9,0.3,-1);
glBegin(GL_QUADS); glVertex3f(9,0.3,-13);
glVertex3f(0.1,0,k); glVertex3f(1,0.3,-13);
glVertex3f(0.1,4,k); glEnd();
glVertex3f(0.1,4,k-2); glBegin(GL_LINE_LOOP);
glVertex3f(0.1,0,k-2); glVertex3f(1,0.3,-15);
glEnd(); glVertex3f(9,0.3,-15);
} glVertex3f(9,0.3,-29);
glPopMatrix(); glVertex3f(1,0.3,-29);
glPushMatrix(); glEnd();
glTranslatef(-50,0.1,20); glPopMatrix();
for(k=-2;k>-38;k-=6) glPushMatrix();
{ glTranslatef(-65,0,8);
glBegin(GL_QUADS); glColor3f(1,1,1);
glVertex3f(-0.1,0,k); for(float i=0;i<0.8;i+=0.2)
glVertex3f(-0.1,4,k); for(float j=0;j<9.8;j+=0.2)
glVertex3f(-0.1,4,k-2); {
glVertex3f(-0.1,0,k-2); glBegin(GL_LINE_LOOP);
glEnd(); glVertex3f(j,i,0);
} glVertex3f(j+0.2,i,0);
glPopMatrix(); glVertex3f(j+0.2,i+0.2,0);
glPushMatrix(); glVertex3f(j,i+0.2,0);
glTranslatef(-50,0.1,-20); glEnd();
for(k=-2;k>-18;k-=4) }
{ glPopMatrix();
glPushMatrix(); glBegin(GL_QUADS);
glTranslatef(-65,0,-8); glVertex3f(0,0,0);
glColor3f(1,1,1); glVertex3f(0,0,-40);
for(float i=0;i<0.8;i+=0.2) glVertex3f(-4,0,-40);
for(float j=0;j<9.8;j+=0.2) glVertex3f(-4,0,0);
{ glEnd();
glBegin(GL_LINE_LOOP); glColor3f(1,0.972,0.862);
glVertex3f(j,i,0); glBegin(GL_QUADS);
glVertex3f(j+0.2,i,0); glVertex3f(-4,0,-4);
glVertex3f(j+0.2,i+0.2,0); glVertex3f(-4,0,-36);
glVertex3f(j,i+0.2,0); glVertex3f(-4,2,-36);
glEnd(); glVertex3f(-4,2,-4);
} glEnd();
glPopMatrix(); glColor3f(0,0,0);
for(int i=0;i<15;i+=5) for(k=-2;k>-38;k-=6)
{ {
glPushMatrix(); glBegin(GL_QUADS);
glTranslatef(-70,6+i,20); glVertex3f(-0.1,0,k);
glColor3f(1,0.894,0.709); glVertex3f(-0.1,4,k);
glBegin(GL_QUADS); glVertex3f(-0.1,4,k-2);
glVertex3f(0,0,0); glVertex3f(-0.1,0,k-2);
glVertex3f(20,0,0); glEnd();
glVertex3f(20,0,-4); }
glVertex3f(0,0,-4); glTranslatef(0,0,-40);
glEnd(); glColor3f(1,0.894,0.709);
glColor3f(1,0.972,0.862); glBegin(GL_QUADS);
glBegin(GL_QUADS); glVertex3f(0,0,0);
glVertex3f(4,0,-4); glVertex3f(-20,0,0);
glVertex3f(16,0,-4); glVertex3f(-20,0,4);
glVertex3f(16,2,-4); glVertex3f(0,0,4);
glVertex3f(4,2,-4); glEnd();
glEnd(); glColor3f(1,0.972,0.862);
glColor3f(0,0,0); glBegin(GL_QUADS);
for(k=2;k<18;k+=4) glVertex3f(-4,0,4);
{ glVertex3f(-16,0,4);
glBegin(GL_QUADS); glVertex3f(-16,2,4);
glVertex3f(k,0,-0.1); glVertex3f(-4,2,4);
glVertex3f(k,4,-0.1); glEnd();
glVertex3f(k+2,4,-0.1); glColor3f(0,0,0);
glVertex3f(k+2,0,-0.1); for(k=-2;k>-18;k-=4)
glEnd(); {
} glBegin(GL_QUADS);
glPushMatrix(); glVertex3f(k,0,0.1);
glTranslatef(20,0,0); glVertex3f(k,4,0.1);
glColor3f(1,0.894,0.709); glVertex3f(k-2,4,0.1);
glVertex3f(k-2,0,0.1); glBegin(GL_QUADS);
glEnd(); glVertex3f(k,0,-0.1);
} glVertex3f(k,4,-0.1);
glPopMatrix(); glVertex3f(k+2,4,-0.1);
glColor3f(1,0.894,0.709); glVertex3f(k+2,0,-0.1);
glBegin(GL_QUADS); glEnd();
glVertex3f(0,0,0); }
glVertex3f(0,0,-40); for(k=-2;k>-38;k-=6)
glVertex3f(4,0,-40); {
glVertex3f(4,0,0); glBegin(GL_QUADS);
glEnd(); glVertex3f(0.1,0,k);
glColor3f(1,0.972,0.862); glVertex3f(0.1,4,k);
glBegin(GL_QUADS); glVertex3f(0.1,4,k-2);
glVertex3f(4,0,-4); glVertex3f(0.1,0,k-2);
glVertex3f(4,0,-36); glEnd();
glVertex3f(4,2,-36); }
glVertex3f(4,2,-4); glPopMatrix();
glEnd(); glPushMatrix();
glColor3f(0,0,0); glTranslatef(-50,0.1,-30);
for(k=-2;k>-38;k-=6) for(k=-2;k>-38;k-=6)
{ {
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex3f(0.1,0,k); glVertex3f(-0.1,0,k);
glVertex3f(0.1,4,k); glVertex3f(-0.1,4,k);
glVertex3f(0.1,4,k-2); glVertex3f(-0.1,4,k-2);
glVertex3f(0.1,0,k-2); glVertex3f(-0.1,0,k-2);
glEnd(); glEnd();
} }
glPopMatrix(); glPopMatrix();
} glPushMatrix();
} glTranslatef(-50,0.1,-70);
void disp_mba() //mba block interiors for(k=-2;k>-18;k-=4)
{int k; {
glPushMatrix(); glBegin(GL_QUADS);
glTranslatef(-70,0.1,-30); glVertex3f(k,0,0.1);
glColor3f(0.5,0.5,0.5); glVertex3f(k,4,0.1);
glBegin(GL_QUADS); glVertex3f(k-2,4,0.1);
glVertex3f(0,0,0); glVertex3f(k-2,0,0.1);
glVertex3f(20,0,0); glEnd();
glVertex3f(20,0,-40); }
glVertex3f(0,0,-40); glPopMatrix();
glEnd(); for(int i=0;i<15;i+=5)
glColor3f(0,0,0); {
for(k=2;k<18;k+=4) glPushMatrix();
{ glTranslatef(-70,6+i,-30);
glColor3f(1,0.894,0.709); glVertex3f(-0.1,4,k);
glBegin(GL_QUADS); glVertex3f(-0.1,4,k-2);
glVertex3f(0,0,0); glVertex3f(-0.1,0,k-2);
glVertex3f(20,0,0); glEnd();
glVertex3f(20,0,-4); }
glVertex3f(0,0,-4); glTranslatef(0,0,-40);
glEnd(); glColor3f(1,0.894,0.709);
glColor3f(1,0.972,0.862); glBegin(GL_QUADS);
glBegin(GL_QUADS); glVertex3f(0,0,0);
glVertex3f(4,0,-4); glVertex3f(-20,0,0);
glVertex3f(16,0,-4); glVertex3f(-20,0,4);
glVertex3f(16,2,-4); glVertex3f(0,0,4);
glVertex3f(4,2,-4); glEnd();
glEnd(); glColor3f(1,0.972,0.862);
glColor3f(0,0,0); glBegin(GL_QUADS);
for(k=2;k<18;k+=4) glVertex3f(-4,0,4);
{ glVertex3f(-16,0,4);
glBegin(GL_QUADS); glVertex3f(-16,2,4);
glVertex3f(k,0,-0.1); glVertex3f(-4,2,4);
glVertex3f(k,4,-0.1); glEnd();
glVertex3f(k+2,4,-0.1); glColor3f(0,0,0);
glVertex3f(k+2,0,-0.1); for(k=-2;k>-18;k-=4)
glEnd(); {
} glBegin(GL_QUADS);
glPushMatrix(); glVertex3f(k,0,0.1);
glTranslatef(20,0,0); glVertex3f(k,4,0.1);
glColor3f(1,0.894,0.709); glVertex3f(k-2,4,0.1);
glBegin(GL_QUADS); glVertex3f(k-2,0,0.1);
glVertex3f(0,0,0); glEnd();
glVertex3f(0,0,-40); }
glVertex3f(-4,0,-40); glPopMatrix();
glVertex3f(-4,0,0); glColor3f(1,0.894,0.709);
glEnd(); glBegin(GL_QUADS);
glColor3f(1,0.972,0.862); glVertex3f(0,0,0);
glBegin(GL_QUADS); glVertex3f(0,0,-40);
glVertex3f(-4,0,-4); glVertex3f(4,0,-40);
glVertex3f(-4,0,-36); glVertex3f(4,0,0);
glVertex3f(-4,2,-36); glEnd();
glVertex3f(-4,2,-4); glColor3f(1,0.972,0.862);
glEnd(); glBegin(GL_QUADS);
glColor3f(0,0,0); glVertex3f(4,0,-4);
for(k=-2;k>-38;k-=6) glVertex3f(4,0,-36);
{ glVertex3f(4,2,-36);
glBegin(GL_QUADS); glVertex3f(4,2,-4);
glVertex3f(-0.1,0,k); glEnd();
glColor3f(0,0,0); glBegin(GL_QUADS);
for(k=-2;k>-38;k-=6) glVertex3f(stair[0][0]-x,stair[0][1]-
{ y,stair[0][2]+z);
glBegin(GL_QUADS); glVertex3f(stair[1][0]+x,stair[1][1]-
glVertex3f(0.1,0,k); y,stair[1][2]+z);
glVertex3f(0.1,4,k); glVertex3f(stair[2][0]+x,stair[2][1]-y,stair[2][2]-
glVertex3f(0.1,4,k-2); z);
glVertex3f(0.1,0,k-2); glVertex3f(stair[3][0]-x,stair[3][1]-y,stair[3][2]-
glEnd(); z);
} glEnd();
glPopMatrix(); glColor3f(0.933,0.913,0.8);
} glBegin(GL_QUADS);
glVertex3f(stair[0][0]-x,stair[0][1]-
} y,stair[0][2]+z);
class temple //construction of temple glVertex3f(stair[0][0]-x,stair[0][1]-1-
{ y,stair[0][2]+z);
float stair[4][3]; glVertex3f(stair[1][0]+x,stair[1][1]-1-
float room[8][3]; y,stair[1][2]+z);
float ceil[6][3]; glVertex3f(stair[1][0]+x,stair[1][1]-
public: y,stair[1][2]+z);
temple()
{ glVertex3f(stair[1][0]+x,stair[1][1]-
stair[0][0]=0;stair[0][1]=0;stair[0][2]=0; y,stair[1][2]+z);
stair[1][0]=12;stair[1][1]=0;stair[1][2]=0; glVertex3f(stair[1][0]+x,stair[1][1]-1-
stair[2][0]=12;stair[2][1]=0;stair[2][2]=-12; y,stair[1][2]+z);
stair[3][0]=0;stair[3][1]=0;stair[3][2]=-12; glVertex3f(stair[2][0]+x,stair[2][1]-1-y,stair[2][2]-
z);
room[0][0]=0;room[0][1]=0;room[0][2]=0; glVertex3f(stair[2][0]+x,stair[2][1]-y,stair[2][2]-
room[1][0]=0;room[1][1]=6;room[1][2]=0; z);
room[2][0]=0;room[2][1]=6;room[2][2]=-7;
room[3][0]=0;room[3][1]=0;room[3][2]=-7; glVertex3f(stair[2][0]+x,stair[2][1]-y,stair[2][2]-
room[4][0]=7;room[4][1]=0;room[4][2]=-7; z);
room[5][0]=7;room[5][1]=6;room[5][2]=-7; glVertex3f(stair[3][0]-x,stair[3][1]-y,stair[3][2]-
room[6][0]=7;room[6][1]=6;room[6][2]=0; z);
room[7][0]=7;room[7][1]=0;room[7][2]=0; glVertex3f(stair[3][0]-x,stair[3][1]-1-y,stair[3][2]-
ceil[0][0]=0;ceil[0][1]=6;ceil[0][2]=4; z);
ceil[1][0]=3.5;ceil[1][1]=9;ceil[1][2]=4; glVertex3f(stair[2][0]+x,stair[2][1]-1-y,stair[2][2]-
ceil[2][0]=7;ceil[2][1]=6;ceil[2][2]=4; z);
ceil[3][0]=7;ceil[3][1]=6;ceil[3][2]=-9;
ceil[4][0]=3.5;ceil[4][1]=9;ceil[4][2]=-9; glVertex3f(stair[3][0]-x,stair[3][1]-y,stair[3][2]-
ceil[5][0]=0;ceil[5][1]=6;ceil[5][2]=-9; z);
} glVertex3f(stair[0][0]-x,stair[0][1]-
void disp_stair(int x, int y, int z) y,stair[0][2]+z);
{ glVertex3f(stair[0][0]-x,stair[0][1]-1-
glColor3f(1,0.960,0.933); y,stair[0][2]+z);
glVertex3f(stair[3][0]-x,stair[3][1]-1-y,stair[3][2]- glColor3f(0.933,0.866,0.509);
z); glBegin(GL_POLYGON);
glEnd(); glVertex3fv(ceil[2]);
} glVertex3fv(ceil[1]);
void disp_room() glVertex3fv(ceil[4]);
{ glVertex3fv(ceil[3]);
glColor3f(0.803,0.803,0.756); glEnd();
glBegin(GL_QUADS); glBegin(GL_POLYGON);
glVertex3fv(room[0]); glVertex3fv(ceil[0]);
glVertex3fv(room[1]); glVertex3fv(ceil[1]);
glVertex3fv(room[2]); glVertex3fv(ceil[4]);
glVertex3fv(room[3]); glVertex3fv(ceil[5]);
glVertex3fv(room[3]); glEnd();
glVertex3fv(room[2]); }
glVertex3fv(room[5]); void draw_pil()
glVertex3fv(room[4]); {
glVertex3fv(room[4]); GLUquadricObj *quadratic;
glVertex3fv(room[5]); quadratic = gluNewQuadric();
glVertex3fv(room[6]); glPushMatrix();
glVertex3fv(room[7]); glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
glVertex3fv(room[1]); glColor3f(0.933,0.866,0.509);
glVertex3fv(room[2]); gluCylinder(quadratic,0.5,0.5,6.0f,32,32);
glVertex3fv(room[5]); glPopMatrix();
glVertex3fv(room[6]); }
glVertex3fv(room[0]); void draw_mesh()
glVertex3f(room[0][0]+1,room[0][1],room[0][2]); {
glVertex3f(room[1][0]+1,room[1][1],room[1][2]); glColor3f(1,0.843,0);
glVertex3fv(room[1]); for(float i=0;i<0.9;i+=0.2)
glVertex3fv(room[7]); for(float j=0;j<6;j+=0.2)
glVertex3f(room[7][0]-1,room[7][1],room[7][2]); {
glVertex3f(room[6][0]-1,room[6][1],room[6][2]); glBegin(GL_LINE_LOOP);
glVertex3fv(room[6]); glVertex3f(i,j,0);
glEnd(); glVertex3f(i+0.2,j,0);
} glVertex3f(i+0.2,j+0.2,0);
void disp_ceil() glVertex3f(i,j+0.2,0);
{ glEnd();
glColor3f(1,0.843,0); }
glBegin(GL_TRIANGLES); }
glVertex3fv(ceil[2]); void disp_temple()
glVertex3fv(ceil[1]); {
glVertex3fv(ceil[0]); disp_stair(0,0,0);
glVertex3fv(ceil[3]); glPushMatrix();
glVertex3fv(ceil[4]); disp_stair(2,1,2);
glVertex3fv(ceil[5]); disp_stair(4,2,4);
glEnd();
glPopMatrix(); glVertex3fv(structure[0]);
glPushMatrix(); glVertex3fv(structure[1]);
glTranslatef(4,0,-9); glVertex3fv(structure[2]);
glRotatef(-90,0,1,0); glVertex3fv(structure[3]);
disp_room(); glEnd();
disp_ceil(); glBegin(GL_QUADS);
glPushMatrix(); glVertex3fv(structure[0]);
glTranslatef(0.4,0,2.5); glVertex3fv(structure[4]);
draw_pil(); glVertex3fv(structure[7]);
glTranslatef(6.2,0,0); glVertex3fv(structure[3]);
draw_pil(); glEnd();
glPopMatrix(); glBegin(GL_QUADS);
glPushMatrix(); glVertex3fv(structure[4]);
glTranslatef(1.5,0,-3); glVertex3fv(structure[5]);
draw_idol(); glVertex3fv(structure[6]);
glPopMatrix(); glVertex3fv(structure[7]);
glPushMatrix(); glEnd();
glTranslatef(1,0,0); glBegin(GL_QUADS);
draw_mesh(); glVertex3fv(structure[1]);
glTranslatef(4,0,0); glVertex3fv(structure[2]);
draw_mesh(); glVertex3fv(structure[6]);
glPopMatrix(); glVertex3fv(structure[5]);
glPopMatrix(); glEnd();
}
}temp; if(structure[1][0]>(-1*structure[4][2]))
class building //construction of the block buildings {
{ for(float i=10; i<structure[2][1]; i+=10)
float structure[8][3]; {
public: glPushMatrix();
building(float a, float b, float c) glTranslatef(0,i,0);
{ for(float j=5; j<structure[1][0]; j+=15)
structure[0][0]=0;structure[0][1]=0;structure[0][2]=0; {
structure[1][0]=a;structure[1][1]=0;structure[1][2]=0; glColor3f(0,0,0);
structure[2][0]=a;structure[2][1]=b;structure[2][2]=0; glBegin(GL_POLYGON);
structure[3][0]=0;structure[3][1]=b;structure[3][2]=0; glVertex3f(j,0,0.1);
structure[4][0]=0;structure[4][1]=0;structure[4][2]=c; glVertex3f(j+5,0,0.1);
structure[5][0]=a;structure[5][1]=0;structure[5][2]=c; glVertex3f(j+5,5,0.1);
structure[6][0]=a;structure[6][1]=b;structure[6][2]=c; glVertex3f(j,5,0.1);
structure[7][0]=0;structure[7][1]=b;structure[7][2]=c; glEnd();
} glBegin(GL_POLYGON);
void disp_build(char text[15],char side='/0') glVertex3f(j,0,structure[4][2]-0.1);
{ glVertex3f(j+5,0,structure[4][2]-0.1);
float door[3]; glVertex3f(j+5,5,structure[4][2]-0.1);
glColor3f(1,0.980,0.980); glVertex3f(j,5,structure[4][2]-0.1);
glBegin(GL_QUADS); glEnd();
} glTranslatef(0,i,0);
for(float j=0;j<structure[1][0];j+=15) for(float j=-5; j>structure[4][2]; j-=15)
{ {
glColor3f(1,0,0); glColor3f(0,0,0);
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
glVertex3f(j,-10,0.1); glVertex3f(-0.1,0,j);
glVertex3f(j+2,-10,0.1); glVertex3f(-0.1,0,j-5);
glVertex3f(j+2,10,0.1); glVertex3f(-0.1,5,j-5);
glVertex3f(j,10,0.1); glVertex3f(-0.1,5,j);
glEnd(); glEnd();
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
glVertex3f(j,-10,structure[4][2]-0.1); glVertex3f(structure[1][0]+0.1,0,j);
glVertex3f(j+2,-10,structure[4][2]-0.1); glVertex3f(structure[1][0]+0.1,0,j-5);
glVertex3f(j+2,10,structure[4][2]-0.1); glVertex3f(structure[1][0]+0.1,5,j-5);
glVertex3f(j,10,structure[4][2]-0.1); glVertex3f(structure[1][0]+0.1,5,j);
glEnd(); glEnd();
} }
glPopMatrix(); for(float j=0;j>structure[4][2];j-=15)
} {
glColor3f(0,0,0); glColor3f(1,0,0);
door[0]=(structure[1][0]/2); glBegin(GL_POLYGON);
glBegin(GL_POLYGON); glVertex3f(-0.1,-10,j);
glVertex3f(door[0]-4,0,0.2); glVertex3f(-0.1,-10,j-2);
glVertex3f(door[0]+4,0,0.2); glVertex3f(-0.1,10,j-2);
glVertex3f(door[0]+4,7,0.2); glVertex3f(-0.1,10,j);
glVertex3f(door[0]-4,7,0.2); glEnd();
glEnd(); glBegin(GL_POLYGON);
glPushMatrix(); glVertex3f(structure[1][0]+0.1,-10,j);
glTranslatef(10,0,3); glVertex3f(structure[1][0]+0.1,-10,j-2);
draw_board(); glVertex3f(structure[1][0]+0.1,10,j-2);
glPushMatrix(); glVertex3f(structure[1][0]+0.1,10,j);
glTranslatef(1,2,0.1); glEnd();
glScalef(.01, .01, .01); }
glLineWidth(2); glPopMatrix();
glColor3f(0,0,0); }
for (int c=0; text[c] != 0; ++c) door[2]=(structure[4][2]/2);
glutStrokeCharacter(GLUT_STROKE_ROMAN, text[c]); door[0]=structure[1][0];
glPopMatrix(); glColor3f(0,0,0);
glPopMatrix(); if(side=='r')
} {
else glBegin(GL_POLYGON);
{ glVertex3f(door[0]+0.2,0,door[2]-4);
for(float i=10; i<structure[2][1]; i+=10) glVertex3f(door[0]+0.2,0,door[2]+4);
{ glVertex3f(door[0]+0.2,7,door[2]+4);
glPushMatrix(); glVertex3f(door[0]+0.2,7,door[2]-4);
glEnd(); glBegin(GL_LINES);
glPushMatrix();
glTranslatef(door[0]+3,0,-2); glVertex3f(structure[0][0],i,structure[0][2]+0.1);
glRotatef(90,0,1,0);
draw_board(); glVertex3f(structure[1][0],i,structure[0][2]+0.1);
glPushMatrix(); glVertex3f(structure[0][0]-
glTranslatef(1,2,0.1); 0.1,i,structure[0][2]);
glScalef(.01, .01, .01); glVertex3f(structure[0][0]-
glLineWidth(2); 0.1,i,structure[4][2]);
glColor3f(0,0,0); glVertex3f(structure[4][0],i,structure[4][2]-
for (int c=0; text[c] != 0; ++c) 0.1);
glutStrokeCharacter(GLUT_STROKE_ROMAN, glVertex3f(structure[5][0],i,structure[4][2]-
text[c]); 0.1);
glPopMatrix();
glPopMatrix(); glVertex3f(structure[5][0]+0.1,i,structure[5][2]);
}
else if(side=='l') glVertex3f(structure[1][0]+0.1,i,structure[1][2]);
{ glEnd();
glBegin(GL_POLYGON); }
glVertex3f(-0.2,0,door[2]-4); glPopMatrix();
glVertex3f(-0.2,0,door[2]+4); }
glVertex3f(-0.2,7,door[2]+4); };
glVertex3f(-0.2,7,door[2]-4); building canteen(20,30,-30);
glEnd(); building mech(20,40,-40);
glPushMatrix(); building mba(20,40,-40);
glTranslatef(-3,0,-10); building admin(40,30,-20);
glRotatef(-90,0,1,0); building ec(40,30,-30);
draw_board(); building cs(30,40,-40);
glPushMatrix(); void loop(float x,float y,float z) //the basket loop of
glTranslatef(1,2,0.1); the basketball post
glScalef(.01, .01, .01); {
glLineWidth(2); float xx,zz,d;
glColor3f(0,0,0); glColor3f(1,0,0);
for (int c=0; text[c] != 0; ++c) glPointSize(2);
glutStrokeCharacter(GLUT_STROKE_ROMAN, glBegin(GL_POINTS);
text[c]); for(int i=0;i<360;i++)
glPopMatrix(); {
glPopMatrix(); d=i*(180/3.14);
} xx=cos(d)+x;
} zz=sin(d)+z;
glPushMatrix(); glVertex3f(xx,y,zz);
glTranslatef(0,10,0); }
glColor3f(0,0,1); glEnd();
for(int i=0;i<structure[2][1]-5;i+=5) }
{
glEnd();
glColor3f(0.545,0.474,0.368); glVertex3f(bordr[3][0],bordr[3][1],bordr[3][2]+t);
glBegin(GL_POLYGON); glVertex3f(bordr[3][0],bordr[3][1]-
glVertex3f(bordr[0][0],bordr[0][1],bordr[0][2]- 1,bordr[3][2]+t);
t); glVertex3f(bordr[2][0],bordr[2][1]-
glVertex3f(bordr[1][0],bordr[1][1],bordr[1][2]- 1,bordr[2][2]+t);
t); glEnd();
glVertex3f(bordr[1][0],bordr[1][1]-1,bordr[1][2]- glColor3f(0.803,0.701,0.545);
t); glBegin(GL_POLYGON);
glVertex3f(bordr[0][0],bordr[0][1]-1,bordr[0][2]- glVertex3f(bordr[3][0],bordr[3][1],bordr[3][2]);
t); glVertex3f(bordr[0][0],bordr[0][1],bordr[0][2]);
glEnd();
glColor3f(0.803,0.701,0.545); glVertex3f(bordr[0][0]+t,bordr[0][1],bordr[0][2]);
glBegin(GL_POLYGON);
glVertex3f(bordr[1][0],bordr[1][1],bordr[1][2]); glVertex3f(bordr[3][0]+t,bordr[3][1],bordr[3][2]);
glVertex3f(bordr[2][0],bordr[2][1],bordr[2][2]); glEnd();
glVertex3f(bordr[2][0]- glColor3f(0.545,0.474,0.368);
t,bordr[2][1],bordr[2][2]); glBegin(GL_POLYGON);
glVertex3f(bordr[1][0]- glVertex3f(bordr[0][0]+t,bordr[0][1],bordr[0][2]);
t,bordr[1][1],bordr[1][2]);
glEnd(); glVertex3f(bordr[3][0]+t,bordr[3][1],bordr[3][2]);
glColor3f(0.545,0.474,0.368); glVertex3f(bordr[3][0]+t,bordr[3][1]-
glBegin(GL_POLYGON); 1,bordr[3][2]);
glVertex3f(bordr[1][0]- glVertex3f(bordr[0][0]+t,bordr[0][1]-
t,bordr[1][1],bordr[1][2]); 1,bordr[0][2]);
glVertex3f(bordr[2][0]- glEnd();
t,bordr[2][1],bordr[2][2]); glPopMatrix();
glVertex3f(bordr[2][0]-t,bordr[2][1]- }
1,bordr[2][2]); glPushMatrix();
glVertex3f(bordr[1][0]-t,bordr[1][1]- glTranslatef(16.5,-3,-7);
1,bordr[1][2]); glColor3f(0.827,0.827,0.827);
glEnd(); glLineWidth(10);
glColor3f(0.803,0.701,0.545); glBegin(GL_LINE_LOOP);
glBegin(GL_POLYGON); glVertex3f(0,0,0);
glVertex3f(bordr[2][0],bordr[2][1],bordr[2][2]); glVertex3f(0,2,0);
glVertex3f(bordr[3][0],bordr[3][1],bordr[3][2]); glVertex3f(4,2,0);
glVertex3f(4,0,0);
glVertex3f(bordr[3][0],bordr[3][1],bordr[3][2]+t); glEnd();
glPopMatrix();
glVertex3f(bordr[2][0],bordr[2][1],bordr[2][2]+t); glPushMatrix();
glEnd(); glTranslatef(16.5,-3,-33);
glColor3f(0.545,0.474,0.368); glColor3f(0.827,0.827,0.827);
glBegin(GL_POLYGON); glLineWidth(10);
glBegin(GL_LINE_LOOP);
glVertex3f(bordr[2][0],bordr[2][1],bordr[2][2]+t); glVertex3f(0,0,0);
glVertex3f(0,2,0); glBegin(GL_QUADS);
glVertex3f(4,2,0); glVertex3f(-20,0.1,75);
glVertex3f(4,0,0); glVertex3f(40,0.1,75);
glEnd(); glVertex3f(40,0.1,80);
glPopMatrix(); glVertex3f(-20,0.1,80);
} glEnd();
}fball; glBegin(GL_QUADS);
void changeSize(int w, int h) glVertex3f(35,0.1,75);
{ glVertex3f(35,0.1,-70);
float ratio = ((float) w) / ((float) h); // window aspect glVertex3f(40,0.1,-70);
ratio glVertex3f(40,0.1,75);
glMatrixMode(GL_PROJECTION); // projection matrix is active glEnd();
glLoadIdentity(); // reset the projection }
gluPerspective(45.0, ratio, 0.1, 100.0); // perspective void trees() //draw a tree
transformation {
glMatrixMode(GL_MODELVIEW); // return to modelview mode GLUquadricObj *quadratic;
glViewport(0, 0, w, h); // set viewport (drawing area) to GLUquadricObj *quadratic1;
entire window quadratic1 = gluNewQuadric();
} quadratic = gluNewQuadric();
void update(void) glPushMatrix();
{ glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
if (deltaMove) { // update camera position glColor3f(0.721,0.525,0.043);
x += deltaMove*lx * 0.38; gluCylinder(quadratic,1,1,10.0f,32,32);
z += deltaMove*lz * 0.38; glPopMatrix();
} glTranslatef(0,2,0);
if(vertmove==1) y+=0.1; glPushMatrix();
if(vertmove==-1) y-=0.1; float k=0;
restrict(); for(int i=0,j=0;i<3;i++,j+=0.5,k+=0.15)
glutPostRedisplay(); // redisplay everything {
} glTranslatef(0,1.8,0);
void disp_roads() //display the roads in the campus glColor3f(0.133+k,0.545+k,0.133-k);
{ glPushMatrix();
glColor3f(0.411,0.411,0.411); glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS); gluCylinder(quadratic1,4-j,0,4.0f,32,32);
glVertex3f(-40,0.1,90); glPopMatrix();
glVertex3f(-40,0.1,-70); }
glVertex3f(-20,0.1,-70); glPopMatrix();
glVertex3f(-20,0.1,90); }
glEnd(); void draw_arch(char text[5]) //draw the arch
glBegin(GL_QUADS); {
glVertex3f(-20,0.1,55); glColor3f(0,0,1);
glVertex3f(90,0.1,55); glPushMatrix();
glVertex3f(90,0.1,60); glTranslatef(0,3.5,0);
glVertex3f(-20,0.1,60); glScalef(4,7,2);
glEnd(); glutSolidCube(1);
glPopMatrix(); glVertex3f(25,0,-20);
glPushMatrix(); glVertex3f(100,0,-20);
glTranslatef(16,3.5,0); glVertex3f(100,0,20);
glScalef(4,7,2); glVertex3f(25,0,20);
glutSolidCube(1); glEnd();
glPopMatrix(); draw_map();
glPushMatrix(); disp_roads();
glTranslatef(8,9,0); for(int i=-10;i<40;i+=10)
glScalef(20,4,2); {
glutSolidCube(1); glPushMatrix();
glPopMatrix(); glTranslatef(i,0,67);
glPushMatrix(); trees();
glTranslatef(5,8,1.1); glPopMatrix();
glScalef(.02, .02, .02); }
glLineWidth(4.5); for(int i=45;i<90;i+=10)
glColor3f(1,1,1); {
for (int c=0; text[c] != 0; ++c) glPushMatrix();
glutStrokeCharacter(GLUT_STROKE_ROMAN, text[c]); glTranslatef(i,0,65);
glPopMatrix(); trees();
} glPopMatrix();
void display() glPushMatrix();
{ glTranslatef(i,0,75);
glClearColor(0.7,0.7,1,0); trees();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPopMatrix();
glEnable(GL_DEPTH_TEST); }
glLoadIdentity(); for(int i=-10;i<35;i+=10)
gluLookAt( {
x, y, z, glPushMatrix();
x+lx, y, z+lz, glTranslatef(i,0,25);
0.0, 1.0, 0.0); trees();
printf("\nz=%f\tx=%f\n",z,x); glPopMatrix();
glColor3f(0,1,0); }
glBegin(GL_QUADS); glPushMatrix();
glVertex3f(-100,0,100); glTranslatef(-38,0,90);
glVertex3f(100,0,100); draw_arch("RNSIT");
glVertex3f(100,0,20); glPopMatrix();
glVertex3f(-100,0,20); glPushMatrix();
glVertex3f(-100,0,20); glTranslatef(-70,0,80);
glVertex3f(-15,0,20); canteen.disp_build("CANTEEN",'r');
glVertex3f(-15,0,-100); glPopMatrix();
glVertex3f(-100,0,-100); glPushMatrix();
glVertex3f(-15,0,-100); glTranslatef(-65,0,45);
glVertex3f(100,0,-100); crt1.disp_court();
glVertex3f(100,0,-20); glPopMatrix();
glVertex3f(-15,0,-20); glPushMatrix();
glutMainLoop();
}
Fig 1
CHAPTER – 3
RESULT ANALYSIS
3.1 SNAPSHOTS:
Fig3
Fig 2
Fig4
Fig5 Fig7
Fig6
Fig8
3.2 DISCUSSION: The Successful Completion of the project “campus traverse” using some of the OpenGL
Fig 1 of snapshot shows the user can see the collage with the help of camera function This is developed to watch the animation as per the instruction given by the user to know
the working of a college campus.
Fig 2:
Fig 6:
4.3 REFERENCES:
Fig 6 of snapshot shows the civil department.
1. Edward Angel, Interactive Computer Graphics, 5th edition, Addison-Wesley, 2009.
Fig 7:
Fig 7 of snapshot shows the canteen. 2. F.S Hill, JR., Stephen.M.Kelley, Computer Graphics Using OpenGL, 3rd edition, Pearson
Education, 2009.
Fig 8: 3. Donald Hearn & Pauline Baker: Computer Graphics-OpenGL Version,3rd Edition, Pearson
Education,2011.
Fig 8 of snapshot shows the basketball ground.
CHAPTER – 4
CONCLUSION AND FUTURE WORK
4.1 CONCLUSION:
The final conclusion is that by using the appropriate graphical packages called OpenGL.