3d Room Scene
3d Room Scene
BELGAUM-590014
It gives us immense pleasure to present before you our project titled “3D ROOM SCENE”. The joy
and satisfaction that accompany the successful completion of any task would be incomplete
without the mention of those who made it possible. We are glad to express our gratitude towards
our prestigious institution DAYANANDA SAGAR ACADEMY OF TECHNOLOGY AND
MANAGEMENT for providing us with utmost knowledge, encouragement and the maximum
facilities in undertaking this project.
We wish to express a sincere thanks to our respected principal Dr. B. R. Lakshmikantha for all his
support.
We express our deepest gratitude and special thanks to Dr. C. Nandini, Prof. & H.O.D, Dept. Of
Computer Science Engineering, for all her guidance and encouragement.
We sincerely acknowledge the guidance and constant encouragement of our mini- project guide,
Assistant Prof. Mr. Amith and Assistant Prof. Mr. Raghu M.T.
RACHANA K (1DT14CS069)
AND
PRAMIT PAUL (1DT14CS066)
3D ROOM SCENE December 30, 1899
TABLE OF CONTENT
1. INTRODUCTION
1.1 Computer Graphics
1.2 OpenGL Technology
1.3 Project Description
1.4 Functions Used
2. REQUIREMENT SPECIFICATION
2.1 Hardware Requirements
2.2 Software Requirements
3. INTERFACE AND ARCHITECTURE
3.1 Interface
3.2 Architecture
4. IMPLEMENTATION
5. SNAPSHOTS
6. CONCLUSION & FUTURE ENHANCMENTS
REFERENCES
APPENDIX
-User Manual
-Personal Details
Chapter-1
INTRODUCTION
Computers have become a powerful medium for the rapid and economical production of
pictures.
Graphics provide a so natural means of communicating with the computer that they have
become widespread.
Interactive graphics is the most important means of producing pictures since the invention
of photography and television.
We can make pictures of not only the real world objects but also of abstract objects such
as mathematical surfaces on 4D and of data that have no inherent geometry.
A computer graphics system is a computer system with all the components of the general
purpose computer system. There are five major elements in system: input devices,
processor, memory, frame buffer, output devices.4
OpenGL fosters innovation and speeds application development by incorporating a broad set
of rendering, texture mapping, special effects, and other powerful visualization functions.
Developers can leverage the power of OpenGL across all popular desktop and workstation
platforms, ensuring wide application deployment.
OpenGL Available Everywhere: Supported on all UNIX® workstations, and shipped standard
with every Windows 95/98/2000/NT and Mac OS PC, no other graphics API operates on a
wider range of hardware platforms and software environments.
OpenGL runs on every major operating system including Mac OS, Windows (All Versions),
Linux, Open Step, and BeOS; it also works with every major windowing system, including
Win32, Mac OS, Presentation Manager, and X-Window System. OpenGL is callable from
Ada, C, C++, FORTRAN, Python, Perl and Java and offers complete independence from
network protocols and topologies.
In this project, we are implementing a “3D Room Scene” consisting of a Teapot, Table Lamp, a
Laptop, and a Dining Table. There is a 3D wall on which the above mentioned objects are
attached. The objects are placed on slabs with in turn are attached to the wall. The entire 3D
scene can be moved in all the x,y,z directions, and can be viewed accordingly. The Table Lamp
can be switched ON/OFF using the keyboard function. Turning the lamp on illuminates all the
objects in the scene. The 3D Laptop can also be turned ON/OFF. When switched on the laptop
screen displays a Welcome text. The lid of the laptop can also be Opened/Closed, with the help
of keyboard functions. The Teapot is a standard OpenGL teapot placed on the plate.
In front of the wall, a Dining Table is placed, consisting of a table and four chairs. Four plates
are also arranged on top of the table.
w, s, a, d for Rotation.
1.4Functions Used:
This project is developed using Code::Blocks and this project is implemented by making
extensive use of library functions offered by graphics package of OpenGl, a summary of those
functions follows:
glBegin() :
Specifies the primitives that will be created from vertices presented between glBegin and
subsequent glEnd. GL_POLYGON, GL_LINE_LOOP etc.
glEnd(void) :
glPushMatrix() :
glPushMatrix pushes the current matrix stack down by one level, duplicating the current
matrix.
glPopMatrix() :
glPopMatrix pops the top matrix off the stack, destroying the contents of the popped
matrix. Initially, each of the stacks contains one matrix, an identity matrix.
glTranslate() :
glClear() :
glClear takes a single argument that is the bitwise or of several values indicating which
buffer is to be cleared.
GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT,GL_ACCUM_ BUFFER_BIT,
and GL_STENCIL_BUFFER_BIT. Clears the specified buffers to their current clearing
values.
glClearColor() :
Sets the current clearing color for use in clearing color buffers in RGBA mode. The red,
green, blue, and alpha values are clamped if necessary to the range [0, 1]. The default
clearing color is (0, 0, 0, 0), which is black.
glMatrixMode() :
glutInitWindowPosition() :
This API will request the windows created to have an initial position. The arguments x, y
indicate the location of a corner of the window, relative to the entire display.
glLoadIdentity() :
void glLoadIdentity(void);
glutInitWindowSize() :
The API requests windows created to have an initial size. The arguments width and
height indicate the window’s size (in pixels). The initial window size and position are
hints and may be overridden by other requests.
glutInitDisplayMode () :
Specifies the display mode, normally the bitwise OR-ing of GLUT display mode bit
masks. This API specifies a display mode (such as RGBA or color-index, or single or
double-buffered) for windows.
glFlush() :
void glFlush(void);
glutCreateWindow() :
The parameter name specifies any name for window and is enclosed in double quotes.
This opens a window with the set characteristics like display mode, width, height, and so
on. The string name will appear in the title bar of the window system. The value returned
is a unique integer identifier for the window. This identifier can be used for controlling
and rendering to multiple windows from the same application.
glutDisplayFunc() :
Specifies the new display callback function. The API specifies the function that’s called
whenever the contents of the window need to be redrawn. All the routines need to be
redraw the scene are put in display callback function.
glVertex2f() :
The glVertex function commands are used within glBegin/glEnd pairs to specify point,
line, and polygon vertices. The current color, normal, and texture coordinates are
associated with the vertex when glVertex is called. When only x and y are specified, z
defaults to 0.0 and w defaults to 1.0. When x, y, and z are specified, w defaults to 1.0.
This function specifies the keys to be pressed to manipulate the object displayed and the
output window.
glutMainLoop(void) :
glutMainLoop enters the GLUT event processing loop. These routines should be called at
most once in the GLUT program. Once called, these routine will never exit. It will call all
the necessary call back functions that have been registered.
This function is used to make responds to the keys that are pressed from the keyboard.
In this project, these keyboard keys are used to switch on the kit, to choose different
gates, etc.
glColor3f
void glColor3f(GLfloat red, GLfloat green, GLfloat blue);
PARAMETERS:
glRotate():
PARAMETERS:
The glRotated and glRotatef functions multiply the current matrix by a rotation matrix.
gluPerspective():
void gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble
zFar);
PARAMETERS:
fovy : Specifies the field of view angle, in degrees, in the y
direction.
aspect: Specifies the aspect ratio that determines the field of view in the x direction.
The aspect ratio is the ratio of x (width) to y (height).
zNear: Specifies the distance from the viewer to the near clipping plane (always
positive).
zFar : Specifies the distance from the viewer to the far clipping plane (always positive).
Sets up a perspective projection matrix.
glMaterialfv():
void glMaterialfv(GLenum face, GLenum pname, const GLfloat params);
PARAMETERS:
face: The face or faces that are being updated. Must be one of the following:
GL_FRONT, GL_BACK, or GL_FRONT and GL_BACK.
Pname: The material parameter of the face or faces being updated. The
parameters that can be specified using glMaterialfv, and their interpretations by
the lighting equation, are as follows.
The glMaterialfv function specifies material parameters for the lighting model.
glutInit():
glutInit(int *argcp, char **argv);
PARAMETERS:
argcp : A pointer to the program's unmodified argc variable from main. Upon return, the
value pointed to by argcp will be updated, because glutInit extracts any command line
options intended for the GLUT library.
argv : The program's unmodified argv variable from main. Like argcp, the data for
argv will be updated because glutInit extracts any command line options
understood by the GLUT library.
glutInit(&argc,argv);
glutMainLoop ():
void glutMainLoop();
glutMainLoop() enters the glut event
processing loop.
glLightfv():
void glLightfv(GLenum light, GLenum pname, GLfloat *params);
PARAMETERS:
Light: The identifier of a light. The number of possible lights depends on the
implementation, but at least eight lights are supported. They are identified by symbolic
names of the form GL_LIGHTi where i is a value: 0 to GL_MAX_LIGHTS - 1.
Pname: A light source parameter for light. The following symbolic names are accepted:
GL_DIFFUSE: The params parameter contains four integer or floating-point values that
specify the diffuse RGBA intensity of the light. Integer values are mapped linearly such
that the most positive represent able value maps to 1.0, and the most negative represent
able value maps to 1.0. Floating-point values are mapped directly. Neither integer nor
floating-point values are clamped. The default diffuse intensity is (0.0, 0.0, 0.0, 1.0) for
all lights other than light zero. The default diffuse intensity of light zero is (1.0, 1.0, 1.0,
1.0).
maps to 1.0. Floating-point values are mapped directly. Neither integer nor floating-point
values are clamped. The default specular intensity is (0.0, 0.0, 0.0, 1.0) for all lights other
than light zero. The default specular intensity of light zero is (1.0, 1.0, 1.0, 1.0).
GL_AMBIENT: The params contains four integer or floating-point values that specify
the ambient RGBA intensity of the light. Integer values are mapped linearly such that the
most positive represent able value maps to 1.0, and the most negative representable value
maps to -1.0 . Floating-point values are mapped directly. Neither integer nor floating-
point values are clamped. The initial ambient light intensity is (0,0, 0, 1).
glEnable():
glEnable(GL_CULL_FACE);
PARAMETERS:
glDisable():
glDisable(GL_LIGHT0);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT1);
Display Function:
void display() :
In this function, rotation, translation and scaling is done by pushing and popping the
matrix and using the inbuilt glutSolid function. We draw the helicopter, human and
clouds.
Main Function:
In this function, we are creating the window, enabling the mouse and keyboard
functions, initializing the display mode and also enables the 3D view.
void table():
display lid():
void draw():
Chapter-2
REQUIREMENTS SPECIFICATION
2.1 Hardware requirements:
The graphics package has been designed for OpenGL; hence the machine must
Language: C.
Chapter-3
'x' and 'y' keys- Used for Opening/Closing the laptop lid.
3.2 Architecture
Chapter-4
IMPLEMENTATION
This project is implemented using GLUT functions. The keyboard functions are used to control
the viewing directions and motions
The Table lamp is used to switch ON/OFF which illuminates the light on different objects.
The functions used to design the 3D Room Scene is given below-
void lamp()
glPushMatrix();
glColor3f(1.0,1.0,0.0);
glScaled(0.35,0.25,0.35);
glTranslated(-9.7,16,3.7);
glRotated(180,0,1,1);
glutWireSphere(2,60,4);
glPopMatrix();
glPushMatrix();
glColor3f(0.0,0.0,0.0);
glTranslated(-3.4,3.15,1.3);
glutSolidCube(0.8);
glPopMatrix();
glPushMatrix();
glColor3f(1.0,1.0,0.0);
glScaled(0.42,1.3,0.4);
glTranslated(-8.1,3,3.2);
glutSolidSphere(0.3,20,20);
glPopMatrix();
glPushMatrix();
glColor3f(0.5,0.8,0.8);
glTranslated(-3.1,3,1.7);
glScaled(1.0,2,0.5);
glutSolidCube(0.1);
glPopMatrix();
void laptopDraw(){
draw();
paneldraw();
display_lid();
}
paneldraw() is used to create the inner body of the laptop including the keypad, and
if(key=='w')
glutPostRedisplay();
else
if(key=='s')
glutPostRedisplay();
else
if(key=='a')
glutPostRedisplay();
else
if(key=='d')
glutPostRedisplay();
else
if(key=='l')
if(lightFlag == 1){
glDisable(GL_LIGHT0);
lightFlag = 0;
glutPostRedisplay();
else{
glEnable(GL_LIGHT0);
lightFlag = 1;
glutPostRedisplay();
angle1-=5;
if(angle1<=80) angle1=80;
if(angle1<=130) lidFlag1=0;
glutPostRedisplay();
angle1+=5;
if(angle1>=180) angle1=180;
if(angle1>=130) lidFlag1=1;
glutPostRedisplay();
if(onFlag == 0){
onFlag = 1;
welcomeflag = 0;
glutPostRedisplay();
else{
onFlag = 0;
glutPostRedisplay();
void display(void)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glPushMatrix();
glScalef(50,50,50);
glTranslatef(0,-1,-1);
glPushMatrix();
glColor3f(1,1,1);
glScaled(9.5,6.5,0.25);
glTranslated(0.0,0.3,0.0);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0);
glScaled(9.5,0.2,0.3);
glTranslated(0.0,-7.05,0.0);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0);
glScaled(9.5,0.2,0.3);
glTranslated(0.0,26,0.0);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glColor3f(1,0,0);
glScaled(2.5,0.15,2.5);
glTranslated(0,8,0.5);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glColor3f(1,0,0);
glScaled(2.5,0.15,2.5);
glTranslated(-1.4,18,0.5);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glColor3f(1,0,0);
glScaled(2.5,0.15,2.5);
glTranslated(1.4,-0.6,0.5);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glColor3f(1.8,1.5,0.0);
glTranslated(3.5,0.36,1.4);
glutSolidTeapot(0.5);
glPopMatrix();
glPushMatrix();
lamp();
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-100,-27,90);
laptopDraw();
glPopMatrix();
glPushMatrix();
table();
glPopMatrix();
glFlush();
glutSwapBuffers();
Chapter-5
SNAPSHOTS
Chapter-6
CONCLUSION AND FUTURE ENHANCEMENT
Conclusion:
Using OpenGL we thus created and implemented "3D Room Scene". The Project has been
developed as per requirements specified by the Visvesvaraya Technological University as a
partial fulfillment of the Computer Graphics Lab for 6th Semester, Computer Science and
Engineering. All the requirements given have been implemented in the project. This project
makes use of various functions provided by OpenGL. Doing this project has helped us
understand and implement the concepts of OpenGL.
1. The above project can be implemented in a better way in the form of a complete room.
2. We can add more walls and doors to the room, and objects inside the room like,
cupboards, ceiling fan, etc.
3. Similarly, by making more than one room, we can implement a 3D house.
REFERENCES
Books:
Websites:
[1]. www.opengl.org/resources/libraries
[2]. www.openglforum.com
APPENDIX
User Manual:
w, s, a, d for Rotation.
Personal Details