My Project Report
My Project Report
CERTIFICATE
This is to certify that Miss.Prathibhashree.G(3PG07CS037) &
Miss.Priyanka.K(3PG07CS038). studying in 6th semester B.E.,CS&E
Dept, has successfully submitted the project entitled “TWO SIDED
LIGHTING” towards the partial fulfillment for the requirements of Computer
Graphics & Visualization Lab VTU, Belgaum during the academic year 2009-
2010.
Mr.Maltesh.K Prof.MrsVasanthamma.G.
B.E B.E,M. Tech.,
ACKNOWLEDGEMENT
At the very onset we would like to place on record my utter gratefulness to all those
people who helped us in making this project a reality.
Designing and coming up with a project is not easy. Apart from the shear hard work and effort of
the students the enlightenment of our very experienced teachers also play a paramount role
because it is they who guide us in the right direction.
Prathibhashree.G.
Priyanka.K.
INDEX
CONTENTS PAGE
1. Introduction to Graphics
4. Implementation
5. Screenshots
6. Conclusion
7. Bibliography
ABSTRACT
This project illustrates 3Dimensional visualization of a lamp in which light is glown. The light is
glown at both the sides of the lamp.
This program is made interactive by using mouse and menu interface. When the right button is
clicked on output screen, it displays the menu and it allows the user to choose any one of the
options in the menu. When user clicks on any one of the options in the menu the changes is been
made accordingly.
State Machine
The entire graphics system can be treated as a State Machine, a Black Box that contains a
finite state machine. This state machine has inputs that come from the application program.
These inputs may change the state of the machine or can cause the machine to produce a visible
output. From the perspective of the API, graphics functions are of two types: those that define
primitives that flow through a pipeline inside the state machine and those that either change the
state inside the machine or return state information.
Graphics Pipeline
We start with the set of objects and each object comprises of a set of graphical primitives.
Each primitive comprises of a set of vertices. We can think of collection of primitive types and
vertices as defining the geometry of the scene.
These vertices must be processed in a similar manner to form an image in the frame
buffer. If we think in terms of processing the geometry of object to obtain an image, we can
employ four major steps in imaging process.
1. Vertex Processing: This phase carry out co-ordinate transformation and compute color fro
each vertex.
2. Clipping and Primitive Assembly: Clipping must be done on primitive by primitive basis
rather than vertex by vertex basis.
3. Rasterization: The output of the rasterizer is a set of fragments for each primitive.
4. Fragment Processing: This phase takes in the fragments generated by rasterizer and
updates the pixel in the frame buffer.
ATTRIBUTES:
Attributes are the properties of the output primitives that are an attribute
describes how a particular primitive is to be displayed. They include intensity and color
specifications, line styles, text styles and area filling patterns. Functions within this
category can be used to set attributes for an individual primitive calls or group of output
primitives.
INFORMATION STRUCTURES:
A well-designed computer graphics system requires a fast dynamic information
structure. A dynamic information structure as compared to a static information structure
changes with computation.
For example, an array, which is static, contains a fixed number and type of to
remember that while the information need not follow the user’s thinking patterns, the
interface must. In meeting this requirement, the designer has available two basic
methods of structuring information.
INTRODUCTION TO OPENGL
OpenGL which has become a widely accepted standard for developing graphics
applications .It is easy to learn and it possesses most of the characteristics of other popular
graphics system .OpenGL`s extensive capability & well-defined architecture let to a strong
foundation for building 3Dgraphics
OpenGL has advanced concepts including texture mapping, compositing, &
programmable light & shadings.
In this section, we have described some of the built-in functions of OpenGL which are
being used in our project.
glVertex2f
PROTOTYPE
void glVertex2f ( GLfloat x, GLfloat y );
PARAMETERS
x, y specifies the coordinates of a vertex.
DESCRIPTION
glVertex 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.
glClear
PROTOTYPE
void glClear( GLbitfield mask )
PARAMETERS
mask Bitwise OR of masks that indicate the buffers to be cleared. The four
masks are GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT,
GL_ACCUM_BUFFER_BIT and GL_STENCIL_BUFFER_BIT.
DESCRIPTION
glClear clears buffers to the specified values.
glViewport
PROTOTYPE
void glViewport( GLint x,GLint y, GLsizei width,GLsizei height )
PARAMETERS
x, y Specify the lower left corner of the viewport rectanglepixels. The initial value is
(0,0).width, height Specify the width and height of the viewport. When a GL context is first
attached to a window, width
and height are set to the dimensions of that window.
DESCRIPTION
glViewport specifies the affine transformation of x and y from normalized device coordinates to
window coordinates.
glTranslatef
PROTOTYPE
void glTranslatef( GLfloat x, GLfloat y, GLfloat z )
PARAMETERS
x, y, z Specify the x, y, and z coordinates of a translation vector.
DESCRIPTION
glTranslate produces a translation by (x,y,z). The current matrix is multiplied by this translation
matrix, with the product replacing the current matrix.
glRotatef
PROTOTYPE
void glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
PARAMETERS
angle Specifies the angle of rotation, in degrees.
x, y,z Specify the x,y, and z coordinates of a vector, respectively.
DESCRIPTION
glRotate produces a rotation of angle degrees around the vector (x,y,z).
glScalef
PROTOTYPE
void glScalef( GLfloat x, GLfloat y, GLfloat z )
PARAMETERS
x, y, z Specify scale factors along the x, y, and z axes, respectively.
DESCRIPTION
glScale produces a nonuniform scaling along the x, y,and z axes.The three parameters indicate
the desired scale factor along each of the three axes.
PROTOTYPE
void glPushMatrix( void )
void glPopMatrix( void )
DESCRIPTION
glPushMatrix pushes the current matrix stack down by one, duplicating the current matrix.
glPopMatrix pops the current matrix stack, replacing the current matrix with the one below it on
the stack.
glPolygonMode
PROTOTYPE
void glPolygonMode( GLenum face, GLenum mode )
PARAMETERS
face Specifies the polygons that mode applies to.Must be GL_FRONT for front-
facing polygons, GL_BACK for back-facing polygons, or
GL_FRONT_AND_BACK for front- and back-facing polygons.
mode Specifies how polygons will be rasterized. Accepted values are GL_POINT,
GL_LINE, and GL_FILL. The initial value is GL_FILL for both front- and
back-facing polygons.
DESCRIPTION
glPolygonMode controls the interpretation of polygons for rasterization.
glLoadIdentity
PROTOTYPE
void glLoadIdentity( void )
DESCRIPTION
glLoadIdentity replaces the current matrix with the identity matrix.
glShadeModel
PROTOTYPE
void glShadeModel(Glenum mode);
PARAMETERS
mode Specifies a symbolic value representing a shading technique. Accepted values are
GL_FLAT and GL_SMOOTH. The initial value is GL_SMOOTH.
DESCRIPTION
GL primitives can have either flat or smooth shading. Smooth shading, the default, causes
the computed colors of vertices to be interpolated as the primitive is rasterized, typically
assigning different colors to each resulting pixel fragment. Flat shading selects the computed
color of just one vertex and assigns it to all the pixel fragments generated by rasterizing a single
primitive.
glmaterialfv(3)
PROTOTYPE
PARAMETERS
face Specifies which face or faces are being updated. Must be one of GL_FRONT, GL_BACK,
or GL_FRONT_AND_BACK.
pname Specifies the single-valued material parameter of the face or faces that is being updated.
Must be GL_SHININESS.
param Specifies the value that parameter GL_SHININESS will be set to.
DESCRIPTION
glLightfv(3)
PROTOTYPE
PARAMETERS
param Specifies the value that parameter pname of light source light will be set to.
DESCRIPTION
PROTOTYPE
void glEnable( GLenum cap )
void glDisable( GLenum cap )
PARAMETERS
cap Specifies a symbolic constant indicating a GL capability.
DESCRIPTION
glEnable and glDisable enable and disable various capabilities.
Graphics provides one of the most natural means for communicating with a computer since our
highly developed 2D and 3D pattern recognition abilities allow us to perceive and process
pictorial data rapidly and efficiently.
Interactive computer graphics is the most important means of producing pictures since the
invention of photography and television.
INTRODUCTION TO LIGHT:
From physical perspective, a surface can either emit light by self emission,as a light bulb
does,or reflect light from other surfaces that illuminate it. Some surfaces may both reflect light &
emit light from internal physical process.when we look at a point on an object,the color that we
see is determined by multiple interactions among light sources & reflective surfaces.these
interactions are viewed as recursive process.
Interactions between light & objects can be classified into three groups
1.Specular:They appear shiny because most of light that is reflected or scattered close to
angle of reflection.example mirrors are perfectly specular surfaces, light from an incoming light
may be partially absorbeb,obeying rule that angle of incidence is equal to angle of reflection.
2.Diffuse:Perfectly diffuse surfaces scatter light equally in all directions & thus appear the
same for all viewers.
3.Translucent:Allows some light to penetrate the surface & to emerge from another
location on the object.
The two sided lighting was build using OpenGL as most of our applications will be
designed to access OpenGL directly through the functions in three Libraries. Functions in
OpenGL are stored in a library referred to as GL. The second is the OpenGL Utility library. This
library uses only GL functions but contains code for creating common objects and simplifying
viewing. All functions in GLU can be created from the core GL library but application
programmer prefer not to write the code repeatedly. The GLU library is available in all OpenGL
implementations, functions in GLU library begin with letters “glu”.
To interface with the windowing system and to get input from the external devices into
the program which was required, one more library is used. For each major window system there
is a system specific library that provides the ‘glue’ between the window system and OpenGL.
OpenGL Utility Toolkit is a readily available library which provides the minimum functionality
that should be expected in any modern window systems.
The keyboard interface is used to provide the rotation, translation and scaling in specified
direction.
The main algorithm is an infinite loop continuously poling for the keyboard button
interface. When ever the keyboard key is pressed depending on the key operation takes
place. The user can quit the program either by clicking on CLOSE (X) option or press
ESCAPE key.
3: Draw a cylinder oriented along the Z-axis and is open from both sides.
FLOW CHART
START
If
YES
key=Esc
NO
If
Btn=rtbn
Read Mouse
If If If
Op=1 Op=2 Op=3
STOP
IMPLEMENTATION
DEPT OF CSE,PDIT 2009-10 Page 19
Two sided Lighting
PLATFORM:
This project has been developed and implemented using open GL interface. In
corporate this facility includes glut.h header file.
FUNCTION USED IN THE PROJECT:
The following functions mentioned below are used in our project:
glutCreateWindow ("Two Sided Lighting"); This function is the magical thing that makes this
library slightly easier to use This one statement takes all the data you've sent to Glut so far, and
creates a window with the title passed into this function.
glutDisplayFunc (drawscene); This function tells Glut where the main drawing will take place.
Glut will call this function every time that a glutPostRedisplay() function is called and it is the
responsibility of this function to make sure all the necessary drawing stuff gets to the screen.
This function needs to either have been defined prior to the position of your main function in the
same code file, linked in through a header, or it has to have a prototype listed.
glClearColor(0,0,0,0);
This function sets the overall background color of the window. This also sets the color that the
screen will clear to when glClear() is called. This function accepts values on a unit scale – that is,
any values you pass to this function must reside between 0 and 1.
glutMainLoop();
This function tells Glut that you've finished your initialization, and are ready to start. At this
point, control of the program flow passes from your main function to Glut, which loops in the
background, simulating a message loop that you never have to mess with. Most of the code in
your main function after this line may not be executed
glutSwapBuffers();
As all of our drawing thus far has been to the back buffer, and not the screen, this command is
required to take the information on the back buffer, and send it to the front in one massive swap.
This is where what's been drawn previously actually gets sent to the screen.
glutPostRedisplay();
This function alerts Glut that the screen needs to be redrawn, forcing it to call the draw() function
again at the next possible opportunity. By including this immediately after the call to swap the
buffers, we improvise our own display loop that runs as fast as the computer can handle. In
general, you can put this command in any function that might modify what appears on the
screen.
SN