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

My Project Report

The document is a certificate certifying that two students, Prathibhashree.G and Priyanka.K, have successfully completed their project titled "Two Sided Lighting" for their Computer Graphics & Visualization lab. The project demonstrates 3D visualization of a lamp that glows on both sides using OpenGL. The program is made interactive using mouse and menu interfaces that allow the user to rotate the lamp or change the lighting.

Uploaded by

priya_koppal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views

My Project Report

The document is a certificate certifying that two students, Prathibhashree.G and Priyanka.K, have successfully completed their project titled "Two Sided Lighting" for their Computer Graphics & Visualization lab. The project demonstrates 3D visualization of a lamp that glows on both sides using OpenGL. The program is made interactive using mouse and menu interfaces that allow the user to rotate the lamp or change the lighting.

Uploaded by

priya_koppal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Two sided Lighting

Bellary V.V. Sangha’s


PROUDHADEVARAYA INSTITUTE OF TECHNOLOGY
T.B.DAM,HOSPET-583201
Bellary Dist,Karnataka

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

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.

Signature of the Guide Signature of the HOD

Mr.Maltesh.K Prof.MrsVasanthamma.G.
B.E B.E,M. Tech.,

DEPT OF CSE,PDIT 2009-10 Page 1


Two sided Lighting

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.

In this regard we like to thank our Principal, Dr.P.Khageshan,(M.E.P.hd) for providing


us with all the facilities we asked for in this college.We are extremely grateful to our very own
and beloved HOD, Prof, Mrs.Vasanthamma.G,(M.tech) for having accepted to patronize us in
the apt direction with all her wisdom.We would like to express our heartfelt gratitude towards
our inspiring faculty Mr.Maltesh (B.E)whose firm belief in our capabilities and moral support to
bring our potential to the forefront has played a major role in accomplishment of this project.Last
but not the least, we thank our beloved friends for having supported us with all their strength and
might.

Prathibhashree.G.
Priyanka.K.

DEPT OF CSE,PDIT 2009-10 Page 2


Two sided Lighting

INDEX
CONTENTS PAGE
1. Introduction to Graphics

2. Software Requirement Specification

3. Analysis and Design

4. Implementation

5. Screenshots

6. Conclusion

7. Bibliography

DEPT OF CSE,PDIT 2009-10 Page 3


Two sided Lighting

ABSTRACT

OpenGL is a graphics application programming interface (API). OpenGL is not in itself a


programming language, like C++, but functions as an API which can be used as a software
development tool for graphics applications. The term Open is significant in that OpenGL is
operating system independent. GL refers to graphics language.

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.

The menu interface includes following options:


1. Motion
2. Two Sided Lighting
3. One Sided Lighting

 When the motion option is chosen:


The lamp rotates and is shown in a different view.

 When the two sided option is chosen:


The lamp glows on both the sides.

 When the one sided option is chosen


The lamp glows on one side.

DEPT OF CSE,PDIT 2009-10 Page 4


Two sided Lighting

INTRODUCTION TO COMPUTER GRAPHICS


Computer Graphics is concerned with all aspects of producing pictures or images using a
Computer.

A typical Computer Graphics System comprises of the following major elements:


1. Input Devices
2. Processor
3. Memory
4. Frame Buffer
5. Output Devices

Raster: A picture is produced as an Array of elements. Each picture is a single bit


representation of 0’s and 1’s.
Frame Buffer: Pixels are stored in a part of memory called as Frame Buffer.
Resolution: The number of pixels present in a frame buffer that determines the detail of the
image.
Depth or Precision: Number of bits that are used for each pixel, determines the properties such
as how many colors can be represented on a given system.

The OpenGL API


OpenGL is a software interface to graphics hardware. This interface consists of about 120
distinct commands, which we use to specify the objects and operations needed to produce
interactive three-dimensional applications.
OpenGL is designed as a Streamlined, Hardware-independent Interface to be
implemented on many different hardware platforms. To achieve these qualities, no commands
for performing windowing tasks or obtaining User Input are included in OpenGL; instead, we
must work through whatever Windowing System controls the particular hardware we are using.

DEPT OF CSE,PDIT 2009-10 Page 5


Two sided Lighting

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.

DEPT OF CSE,PDIT 2009-10 Page 6


Two sided Lighting

FEATURES OF COMPUTER GRAPHICS


OUTPUT PRIMITIVES:
The basic building blocks for pictures are referred to as output primitives to
include strings and geometric figures such as points, lines, circles, curves and polygons
etc. and shapes defined with array of color points. Routines for generating output
primitives provide the basic tools for constructing pictures.

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.

DEPT OF CSE,PDIT 2009-10 Page 7


Two sided Lighting

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.

glBegin AND glEnd


PROTOYPE
Void glBegin (GLenum mode)
Void glEnd( void )
PARAMETERS
mode Specifies the primitives that will be created from vertices presented
between glBegin and the subsequent glEnd. Ten symbolic constants are
accepted: GL_POINTS, GL_LINES,GL_LINE_STRIP,
GL_LINE_LOOP, GL_TRIANGLES, GL_TRIANGLE_STRIP,
GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, and
GL_POLYGON.
DESCRIPTION
glBegin and glEnd delimit the vertices that define a primitive or a group of like
primitives.glBegin accepts a single argument that specifies in which of ten ways the vertices are
interpreted.

DEPT OF CSE,PDIT 2009-10 Page 8


Two sided Lighting

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 )

DEPT OF CSE,PDIT 2009-10 Page 9


Two sided Lighting

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.

DEPT OF CSE,PDIT 2009-10 Page 10


Two sided Lighting

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.

glPushMatrix and glPopMatrix

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

DEPT OF CSE,PDIT 2009-10 Page 11


Two sided Lighting

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.

DEPT OF CSE,PDIT 2009-10 Page 12


Two sided Lighting

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

void glMaterialfv( GLenum face, GLenum pname, GLfloat param )

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

glMaterialfv assigns values to material parameters

glLightfv(3)

PROTOTYPE

void glLightf( GLenum light, GLenum pname, GLfloat param )

PARAMETERS

light Specifies a light.

Pname Specifies a single-valued light source parameter for light.

DEPT OF CSE,PDIT 2009-10 Page 13


Two sided Lighting

param Specifies the value that parameter pname of light source light will be set to.

DESCRIPTION

glLight sets the values of individual light source parameters.

glEnable AND glDisable

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.

ADVANTAGES OF COMPUTER GRAPHICS:

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.

DEPT OF CSE,PDIT 2009-10 Page 14


Two sided Lighting

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.

DEPT OF CSE,PDIT 2009-10 Page 15


Two sided Lighting

SOFTWARE REQUIREMENT SPECIFICATION

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.

DEPT OF CSE,PDIT 2009-10 Page 16


Two sided Lighting

ANALYSIS AND DESIGN

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.

Algorithm for Two Sided Lighting:

1: Initialize Display mode and set RGB colors.

2: Define Light and the material properties.

3: Draw a cylinder oriented along the Z-axis and is open from both sides.

4: Declare function for mouse interface.

5: Create a menu having different options for motion and lighting.

6: Display a cylinder having a light source.

Check for the mouse button pressed:


 If right button is clicked then display the menu.
 If first option is chosen then rotate the cylinder.
 If second option is chosen then glow the light on both sides.
 If third option is chosen then glow the light on one side.
 If key pressed is a Escape key then exit from the window.

DEPT OF CSE,PDIT 2009-10 Page 17


Two sided Lighting

FLOW CHART

START

Initialize display modes and set RGB values

Draw a cylinder along Z-axis

Declare functions for mouse interface

Display cylinder having light sources

DEPT OF CSE,PDIT 2009-10 Page 18


Two sided Lighting

If
YES
key=Esc

NO

If
Btn=rtbn

Read Mouse

If If If
Op=1 Op=2 Op=3

Motion Two sided lighting One sided lighting

Display Display Display

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:

glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); This function sets


the display mode. The parameters here specify that the color mode will be RGBA (red, green,
blue, alpha), and that the screen will be double-buffered. There is a list of options available for
this function in the Glut documentation, but for now all you really need to know about this call is
that double buffering is better than single as it helps to reduce screen flicker when a lot of stuff
starts taking place on the screen.

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);

DEPT OF CSE,PDIT 2009-10 Page 20


Two sided Lighting

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.

DEPT OF CSE,PDIT 2009-10 Page 21


Two sided Lighting

DEPT OF CSE,PDIT 2009-10 Page 22


Two sided Lighting

SN

DEPT OF CSE,PDIT 2009-10 Page 23


Two sided Lighting

DEPT OF CSE,PDIT 2009-10 Page 24


Two sided Lighting

DEPT OF CSE,PDIT 2009-10 Page 25

You might also like