Cgfull
Cgfull
Cgfull
INTRODUCTION
Computer Graphics is one of the most powerful and interesting facets of computers. There
is a lot we can do in graphics apart from drawing figures of various shapes. All video games,
animation, multimedia predominantly works using computer graphics. There are so many
applications of computer graphics, which make it significant. Computer graphics is
concerned with all aspects of producing pictures or images using a computer.
distinct commands, which we use to specify the objects and operations needed to produce
interactive 3-dimensional applications.
Page 1
CHAPTER 1 INTRODUCTION
OpenGL has become a widely accepted standard for developing graphics applications. It
can be used to implement several effects. Hence this project has become more colorful
because of the effects implemented using OpenGL.
• Arrange the objects in three-dimensional space and select the desired vantage point
for viewing the composed scene.
• Calculate the color of all the objects. The color might be explicitly assigned by the
application, determined from specified lighting conditions, obtained by pasting a
texture onto the objects, or some combination of these three actions.
OpenGL defined constants begin with GL_, use all capital letters, and use underscores to
separate words (like GL_COLOR_BUFFER_BIT).The user might also have noticed some
seemingly extraneous letters appended to some command names (for example, the 3f in
glColor3f () and glVertex3f (). It's true that the Color part of the command name glColor3f
() is enough to define the command as one that sets the current color.
OpenGL is a state machine. It can be put into various states (or modes) that then remain in
effect until it is changed. The user can set the current color to white, red, or any other color,
and thereafter every object is drawn with that color until the current set color to something
else. Others control such things as the current viewing and projection transformations, line
and polygon stipple patterns, polygon drawing modes, pixel-packing conventions, positions
and characteristics of lights, and material properties of the objects being drawn. Many state
variables refer to modes that are enabled or disabled with the command glEnable () or
Display Lists
All data, whether it describes geometry or pixels, can be saved in a display list for current
or later use. When a display list is executed, the retained data is sent from the display list
just as if it were sent by the application in immediate mode.
Evaluators
All geometric primitives are eventually described by vertices. Parametric curves and
surfaces may be initially described by control points and polynomial functions called basis
functions. Evaluators provide a method to derive the vertices used to represent the surface
from the control points.
Per-Vertex Operations
For vertex data, next is the "per-vertex operations" stage, which converts the vertices into
primitives. Some vertex data are transformed by 4 x 4 floating-point matrices. Spatial
coordinates are projected from a position in the 3D world to a position on the screen.
Primitive Assembly
Clipping, a major part of primitive assembly, is the elimination of portions of geometry
which fall outside a half-space, defined by a plane. Point clipping simply passes or rejects
vertices; line or polygon clipping can add additional vertices depending upon how the line
Pixel Operations
While geometric data takes one path through the OpenGL rendering pipeline, pixel data
takes a different route. Pixels from an array in system memory are first unpacked from one
of a variety of formats into the proper number of components. Next the data is scaled,
biased, and processed by a pixel map. The results are clamped and then either written into
texture memory or sent to the rasterization step.
Texture Assembly
An OpenGL application may wish to apply texture images onto geometric objects to make
them look more realistic.
Rasterization
Rasterization is the conversion of both geometric and pixel data into fragments. Each
fragment square corresponds to a pixel in the frame buffer. Color and depth values are
assigned for each fragment square.
Fragment Operations
Before values are actually stored into the frame buffer, a series of operations are performed
that may alter or even throw out fragments. All these operations can be enabled or disabled.
REQUIREMENT SPECIFICATIONS
. Hardware Requirements
• Software Requirements
• Functional Requirements
• Non-Functional Requirements
hardware components
PAGE 7
CHAPTER 2 REQUIREMENT SPECIFICATIONS
Program will use windows print APIs to interface with printer.Interface with other software
components or products, including other systems, utility software, databases, and
operating systems.
• GLUT library
• STDLIB library
The application is very self-contained. Robust error handling will be implemented and
code will be object-oriented to allow for easier maintenance and feature additions.
This model runs using Microsoft Visual Studio version 2010 on a Windows XP platform.
2.2.2 Hardware Requirements
There are no rigorous restrictions on the machine configuration. The model should be
capable of working on all machines capable of supporting recent versions of Microsoft
Visual Studio.
• RAM: 1 GB
• Keyboard: Standard
• Mouse: Standard
Requirement Professional
RAM
384 MB of RAM or more (768 MB of RAM or
With MSDN:
MSDN
• Performance has not been tuned for minimum system configuration. Increasing
the RAM above the recommended system configuration will improve
performance, specifically when there are running multiple applications,
working with large projects, or doing enterprise-level development.
• When the Visual Studio installer is started, the default installation location is the
system drive, which is the drive that boots the system. However, the user can
install the application on any drive. Regardless of the application's location, the
installation process installs some files on the system drive. Consequently, make
sure that the required amount of space, as listed in this table, is available on the
system drive regardless of the application's location. Make sure that the required
additional space, as listed in this table, is available on the drive on which it is in
the application is installed.
• The type of media provided with the product determines whether a CD-ROM
drive or DVD-ROM drive is required.
• When an appropriate option is selected from the menu, the required changes
are instantly observed as the output. Hence, the program is efficient.
• Changing the attributes of the Primitive Play is done using mouse functions.
Hence the project is user interactive.
CHAPTER 3
DESIGN PHASE
Design of any software depends on the architecture of the machine on which that software
runs, for which the designer needs to know the system architecture. Design process involves
design of suitable algorithms, modules, subsystems, interfaces etc.
This project has been created using the OpenGL interface along with the
GLUT(OpenGL Library Tool), using the platform Visual C++ 6.0 as a compiling tool. This
project has been designed in a simple and lucid manner so that further developments can be
made, and run on many platforms with a few changes in the code.
3.1 Algorithm:
Step 1: The execution of program starts from main ( ). int
{
Initialize GLUT state Initialize Display Mode Create and name the display window as “3D
CAR SIMULATION “
Handle following functions using glut call back functions
DrawGLScene ( ) //Display call back
ResizeGLScene ( ) //Reshape call back
NormalKey ( ) //Keyboard call back
SpecialKeyFunc ( ) //Special Key board call back
Create_menu ( )
Start event processing loop.
}
Step 2: Create_menu ( )
{
Create the submenu using glutCreateMenu(ColorMenu) Each menu entry is created using
glutAddMenuEntry ()
Create the Main menu using glutCreateMenu(myMenu) This menu helps to select
the mode of car and view effects.
Add submenu to the car colors entry in main menu.
Attach menu to the right mouse button using
glutAttachMenu (GLUT_RIGHT_BUTTON).
}
Step 3: The function called when window is resized.
ResizeGLscene()
{
Perform Transformations Transform( )
}
Step 4: Transformation Routine.
Transform ( )
{
Set the projection using glViewport ( )
Select the projection using glMatrixMode(GL_PROJECTION)
Reset the projection matrix
Calculate aspect ratio of window using gluPerspective ()
Switch back to the model view
}
Step 5: The general OpenGL initialization function to set initial parameters.
InitGL( width, Height)
{
Set background color to white glClearColor(1.0,1.0,1.0,1.0)
Set line width glLineWidth (), Perform Transformations Transform ()
Enable lighting glEnable (GL_LIGHTING)
Set the ambient, diffuse, specular light at specific position using glLightfv
()
}
{
Display_string(x , y, ”string”, font) x, y
specifies position of string to be displayed.
glutSwapBuffers( )
}
Display_string(x, y, string, font)
{
Set raster position using glRasterPos2f(x, y) Set len to
strlen(string) fori=0 to len
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_font,string[i])
}
Step 7: The main display function handled by display call back.
View=0 // to view help screen
DrawGLScene()
{ if view is 0 then
display1( ) else
{
InitGL( )
Enable rotation by along the three axes using
glRotatef( xangle,1.0 ,0.0 ,0.0 )
glRotatef(yangle,0.0, 1.0, 0.0) glRotatef(zangle,
0.0, 0.0, 1.0)
Enable translation by calling glTranslatef (xt, yt, zt)
Enable scaling by calling glScalef(xs, ys, zs) The
car is drawn as 3d object
Body of car drawn specifying points using following function glBegin
(GL_QUADS) //points defined as glVertex3f(x, y, z) glEnd () The
{
Enable lighting
effects } if id=’day
mode’ then
{
Data flow diagrams show how data is processed at different stages in the system. Data
flow models are used to show how data flows through a sequence of processing steps. The
data is transformed at each step before moving on to the next stage. These processing steps
of transformations are program functions when data flow diagrams are used to document a
software design.
The use of space bar allows the user to enter into the display mode. The movement of the
car can be done using left and right arrow keys. The X/x, Y/y, Z/z keys are used for
corresponding rotation in clockwise or anti-clockwise direction. A/a, Q/q, S/s for custom
size collection.U/u, F/f for camera view settings. The escape key enables the user to exit.
The other effects can be viewed by selecting the appropriate menu. The menu can be viewed
by pressing the right mouse button. Menu callback is used to implement these
The above Figure 3.2 shows the Data flow Diagram .The processing of different operations
in this project.
IMPLEMENTATION
Mode - Display mode, normally the bitwise OR-ing of GLUT display mode bit masks.
Description: The initial display mode is used when creating top-level windows, sub
windows, and overlays to determine the OpenGL display mode for the to-be-created
window or overlay.
3. glutCreateWindow( )
glutCreateWindow creates a top-level window.
Usage:intglutCreateWindow(char *name);
y callback parameters indicate the mouse location in window relative coordinates when the
key was pressed. Passing NULL to glutKeyboardFunc disables the generation of keyboard
callbacks.
5.glutMainLoop( )
glutMainLoop enters the GLUT event processing loop.
Usage: void glutMainLoop(void);
Description: glutMainLoop enters the GLUT event processing loop. This routine should
be called at most once in a GLUT program. Once called, this routine will never return. It will
call as necessary any callbacks that have been registered.
5. glMatrixMode( )
The two most important matrices are the model-view and projection matrix. At any time,
the state includes values for both of these matrices, which are initially set to identity
matrices. There is only a single set of functions that can be applied to any type of matrix.
Select the matrix to which the operations apply by first set in the matrix mode, a variable
that is set to one type of matrix and is also part of the state.
6. gluOrtho2D( )
It is used to specify the two dimensional orthographic view. It takes four parameters; they
specify the leftmost corner and rightmost corner of viewing rectangle.
glClear Function
The glClear function clears buffers to preset values. SYNTAX:glClear(GLbitfield
mask);
Where ‘mask’ is Bitwise OR operators of masks that indicate the buffers to be cleared.
The masks used are as follows.
Value Meaning
GL_COLOR_BUFFER_BIT The buffers currently enabled for color writing.
GL_DEPTH_BUFFER_BIT The depth buffer.
glMatrixMode Function
The glMatrixMode function specifies which matrix is the current matrix.
SYNTAX:
voidglMatrixMode(GLenum mode);
where the ‘mode’ indicates the matrix stack that is the target for subsequent matrix
operations. The mode parameter can assume values like GL_PROJECTION which applies
subsequent matrix operations to the projection matrix stack or GL_MODELVIEW etc.
glClearColor function
Sets the present RGBA clear color used when clearing the color buffer. Variables of type
GLclampf are floating-point numbers between 0.0 and 1.0.
SYNTAX: void glClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
glPointSize function
sets the size attribute in pixel
SYNTAX: void glPointSize(GLfloat size); glFlush
function
Forces any buffered OpenGL command to execute. It ensures that points rendered to the
screen as soon as possible.
SYNTAX: void glFlush( );
glutSwapBuffers function
Swaps the front and back buffers.
SYNTAX: void glutSwapBuffers( );
gluOrtho2D function
Defines a two dimensional viewing rectangle in the plane z=0.
SYNTAX: void gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom,
GLdouble top);
MAIN FUNCTION
glutInit Function
Initializes GLUT, if arguments are passed then they are passed from the main and can be
used by the application.
SYNTAX: glutInit(int *argcp, char **argv);
glutInitDisplayMode Function
glutInitDisplayMode sets the initial display mode. SYNTAX:void
glutInitDisplayMode(unsigned int mode); where ‘mode’ is normally the bitwise OR-ing of
GLUT display mode bit masks. Values are below:
GLUT_RGB: An alias for GLUT_RGBA.
GLUT_DOUBLE: Bit mask to select a double buffered window.
GLUT_SINGLE: To select a single buffered window.
GLUT_DEPTH: Bit mask to select a window with a depth buffer.
glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH|GLUT_DOUBLE);
glutCreateWindow Function
glutCreateWindow creates a top-level window with the name contained in the string
‘title’.
SYNTAX:intglutCreateWindow(char *title);
glutMainLoop Function
glutMainLoop enters the GLUT event processing loop. SYNTAX:
void glutMainLoop(void);
glutKeyboardFunc function
Registers the keyboard callback function f in main. The callback function returns the ASCII
code of the key pressed and the position of the mouse.
SYNTAX: void glutKeyboardFunc(void *f(int width, int height);
glutDisplayFunc Function
glutDisplayFunc sets the display callback for the current window.
SYNTAX: void glutDisplayFunc(void (*func)(void));
Source code:
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#include<string.h>
GLint window;
GLint window2;
GLint Xsize=1000;
GLint Ysize=800;
float i,theta;
GLint nml=0,day=1;
char name3[]="PROJECT: 3D CAR SIMULATOR";
GLfloat xt=0.0,yt=0.0,zt=0.0,xw=0.0;
GLfloat tx=295,ty=62;
GLfloat xs=1.0,ys=1.0,zs=1.0;
GLfloat xangle=0.0,yangle=0.0,zangle=0.0,angle=0.0;
GLfloat r=0,g=0,b=1;
GLint light=1;
int count=1,flg=1;
int view=0;
int flag1=0,aflag=1; //
int flag2=0,wheelflag=0;
GLUquadricObj *t;
static void SpecialKeyFunc( int Key, int x, int y )
GLvoid Transform(GLfloat Width, GLfloat Height)
{
glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,Width/Height,0.1,100.0);
glMatrixMode(GL_MODELVIEW);
}
GLvoid InitGL(GLfloat Width, GLfloat Height)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glLineWidth(2.0);
Transform( Width, Height );
t=gluNewQuadric();
gluQuadricDrawStyle(t, GLU_FILL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat diffuseLight[] = { 0.8f, 0.8f, 0.8, 1.0f };
GLfloat specularLight[] = { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat position[] = { 1.5f, 1.0f, 4.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glLightfv(GL_LIGHT0, GL_POSITION, position);
}
GLvoid ReSizeGLScene(GLint Width, GLint Height)
{
if (Height==0) Height=1;
if (Width==0) Width=1;
Transform( Width, Height );
}
void init()
{
glClearColor(0,0,0,0);
glPointSize(5.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,900.0,0.0,600.0,50.0,-50.0);
glutPostRedisplay();
In here we put all the OpenGL and calls to routines which manipulate
the OpenGL state and environment.
void display1(void)
{
glClearColor(1.0,1.0,0.1,1.0);
display_string(180,540,"CITY ENGINEERING COLLEGE",1);
display_string(215,500,name3,1);
display_string(390,470,"HELP",2);
display_string(10,450,"MOUSE",2);
display_string(10,410,"PRESS RIGHT BUTTON FOR MENU",3);
display_string(10,370,"KEYBOARD",2);
display_string(10,340,"X-Y-Z KEYS FOR CORRESPONDING ROTATION",3);
display_string(10,310,"A-S-Q CAR CUSTOM SIZE SELECTION",3);
GLvoid DrawGLScene()
{
if(flag2==1)
{
GLfloat fogcolour[4]={1.0,1.0,1.0,1.0};
if(!aflag){
glBegin(GL_POINTS);
glColor3f(1,1,1);
glPointSize(200.0);
int ccount=0;
float x=10,y=10;
while(ccount<20)
{
glVertex2f(x,y);
x+=10;
y+=10;
if(y>Ysize) y-=10;
if(x>Xsize) x-=10;
ccount++;
}
glEnd();}
glColor3f(1.0,.75,0.0);
glPointSize(30.0);
glBegin(GL_POINTS);
glVertex3f(0.2,0.3,0.3);
glVertex3f(0.2,0.3,0.5);
glEnd();
glPointSize(200.0);
/* top of cube*/
//************************FRONT
BODY****************************************
glColor3f(r,g,b);
glVertex3f( 0.2, 0.4,0.6);
glVertex3f(0.6, 0.5,0.6);
glVertex3f(0.6, 0.5,0.2);
glVertex3f( 0.2,0.4,0.2);
/* bottom of cube*/
glVertex3f( 0.2,0.2,0.6);
glVertex3f(0.6,0.2,0.6);
glVertex3f(0.6,0.2,0.2);
glVertex3f( 0.2,0.2,0.2);
/* front of cube*/
glVertex3f( 0.2,0.2,0.6);
glVertex3f(0.2, 0.4,0.6);
glVertex3f(0.2,0.4,0.2);
glVertex3f( 0.2,0.2,0.2);
/* back of cube.*/
glVertex3f(0.6,0.2,0.6);
glVertex3f(0.6,0.5,0.6);
glVertex3f(0.6,0.5,0.2);
glVertex3f( 0.6,0.2,0.2);
/* left of cube*/
glVertex3f(0.2,0.2,0.6);
glVertex3f(0.6,0.2,0.6);
glVertex3f(0.6,0.5,0.6);
glVertex3f(0.2,0.4,0.6);
/* Right of cube */
glVertex3f(0.2,0.2,0.2);
glVertex3f( 0.6,0.2,0.2);
glVertex3f( 0.6,0.5,0.2);
glVertex3f( 0.2,0.4,0.2);
//************************************************************************
****
glVertex3f(0.7,0.65,0.6);
glVertex3f(0.7,0.65,0.2);
glVertex3f(1.7,0.65,0.2); //top cover
glVertex3f(1.7,0.65,0.6);
//***************************back guard******************************
/* bottom of cube*/
glVertex3f( 2.1,0.2,0.6);
glVertex3f(2.1,0.2,0.2);
glVertex3f(1.8,0.2,0.6);
glVertex3f( 1.8,0.2,0.6);
/* back of cube.*/
glVertex3f(2.1,0.4,0.6);
glVertex3f(2.1,0.4,0.2);
glVertex3f(2.1,0.2,0.2);
glVertex3f(2.1,0.2,0.6);
/* left of cube*/
glVertex3f(1.8,0.2,0.2);
glVertex3f(1.8,0.5,0.2);
glVertex3f(2.1,0.4,0.2);
glVertex3f(2.1,0.2,0.2);
/* Right of cube */
glVertex3f(1.8,0.2,0.6);
glVertex3f(1.8,0.5,0.6);
glVertex3f(2.1,0.4,0.6);
glVertex3f(2.1,0.2,0.6);
//******************MIDDLE BODY************************************
glVertex3f( 0.6, 0.5,0.6);
glVertex3f(0.6, 0.2,0.6);
glVertex3f(1.8, 0.2, 0.6);
glVertex3f(1.8,0.5,0.6);
/* bottom of cube*/
glVertex3f( 0.6,0.2,0.6);
glVertex3f(0.6,0.2,0.2);
glVertex3f(1.8,0.2,0.2);
glVertex3f( 1.8,0.2,0.6);
/* back of cube.*/
glVertex3f(0.6,0.5,0.2);
glVertex3f(0.6,0.2,0.2);
glVertex3f(1.8,0.2,0.2);
glVertex3f(1.8,0.5,0.2);
//*********************ENTER WINDOW**********************************
glColor3f(0.3,0.3,0.3);
glVertex3f( 0.77, 0.63,0.2);
glVertex3f(0.75, 0.5,0.2); //quad front window
glVertex3f(1.27,0.63,.2);
glVertex3f(1.25,0.5,0.2); //quad back window
glVertex3f(1.65,0.5,0.2);
glVertex3f(1.67,0.63,0.2);
glColor3f(r,g,b);
glVertex3f(0.7,0.65,0.2);
glVertex3f(0.7,0.5,.2); //first separation
glVertex3f(0.75,0.5,0.2);
glVertex3f(0.77,0.65,0.2);
glVertex3f(1.2,0.65,0.2);
glVertex3f(1.2,0.5,.2); //second separation
glVertex3f(1.25,0.5,0.2);
glVertex3f(1.27,0.65,0.2);
glVertex3f(1.65,0.65,0.2);
glVertex3f(1.65,0.5,.2); //3d separation
glVertex3f(1.7,0.5,0.2);
glVertex3f(1.7,0.65,0.2);
glColor3f(0.3,0.3,0.3);
glVertex3f( 0.77, 0.63,0.6);
glVertex3f(0.75, 0.5,0.6); //quad front window
glVertex3f(1.2, 0.5, 0.6);
glVertex3f( 1.22,0.63,0.6);
glVertex3f(1.27,0.63,.6);
glVertex3f(1.25,0.5,0.6); //quad back window
glVertex3f(1.65,0.5,0.6);
glVertex3f(1.67,0.63,0.6);
glColor3f(r,g,b);
glVertex3f(0.7,0.65,0.6);
glVertex3f(0.7,0.5,.6); //first separation
glVertex3f(0.75,0.5,0.6);
glVertex3f(0.77,0.65,0.6);
glVertex3f(1.2,0.65,0.6);
glVertex3f(1.2,0.5,.6); //second separation
glVertex3f(1.25,0.5,0.6);
glVertex3f(1.27,0.65,0.6);
glVertex3f(1.65,0.65,0.6);
glVertex3f(1.65,0.5,.6);
glVertex3f(1.7,0.5,0.6);
glVertex3f(1.7,0.65,0.6);
glEnd();
//**************************************************************
glBegin(GL_QUADS);
/* top of cube*/
glColor3f(0.3,0.3,0.3);
glVertex3f( 0.6, 0.5,0.6);
glVertex3f(0.6, 0.5,0.2); //quad front window
glVertex3f(0.7, 0.65, 0.2);
glVertex3f( 0.7,0.65,0.6);
glVertex3f(1.7,0.65,.6);
glVertex3f(1.7,0.65,0.2); //quad back window
glVertex3f(1.8,0.5,0.2);
glVertex3f(1.8,0.5,0.6);
glPushMatrix();
glTranslatef(xw,0,0);
glColor3f(0,1,0);
glVertex3f(-100,0.1,-100);
glVertex3f(-100,0.1,0); //a green surroundings
glVertex3f(100,0.1,0);
glVertex3f(100,0.1,-100);
glColor3f(0.7,0.7,0.7);
glVertex3f(-100,0.1,0);
glVertex3f(-100,0.1,0.45); //a long road
glVertex3f(100,0.1,0.45);
glVertex3f(100,0.1,0);
glColor3f(1.0,0.75,0.0);
glVertex3f(-100,0.1,0.45); //a median
glVertex3f(-100,0.1,0.55);
glVertex3f(100,0.1,0.55);
glVertex3f(100,0.1,0.45);
glColor3f(0.7,0.7,0.7);
glVertex3f(-100,0.1,0.55);
glVertex3f(-100,0.1,1); //a long road
glVertex3f(100,0.1,1);
glVertex3f(100,0.1,0.55);
glColor3f(0,1,0);
glVertex3f(-100,0.1,1);
glVertex3f(-100,0.1,100); //a green surroundings
glVertex3f(100,0.1,100);
glVertex3f(100,0.1,1);
glPopMatrix();
}
glEnd();
if(wheelflag)
{
glPushMatrix();
glTranslatef(xw,0,0);
glColor3f(0.5,.2,0.3);
glBegin(GL_QUADS);
for(i=0;i<200;i+=0.2)
{
glVertex3f(-100+i,0,1);
glVertex3f(-99.9+i,0,1);
glVertex3f(-99.9+i,0.2,1);
glVertex3f(-100+i,0.2,1);
i+=0.5;
}
for(i=0;i<200;i+=0.2)
{
glVertex3f(-100+i,0,0);
glVertex3f(-99.9+i,0,0);
glVertex3f(-99.9+i,0.2,0);
glVertex3f(-100+i,0.2,0);
i+=0.5;
}
glEnd();
glPopMatrix();
}
//************************************************************************
*************************
glBegin(GL_TRIANGLES); /* start drawing the cube.*/
/* top of cube*/
glColor3f(0.3,0.3,0.3);
glVertex3f( 0.6, 0.5,0.6);
glVertex3f( 0.7,0.65,0.6); //tri front window
glVertex3f(0.7,0.5,0.6);
glEnd();
//************IGNITION SYSTEM**********************************
glPushMatrix();
glColor3f(0.7,0.7,0.7);
glTranslatef(1.65,0.2,0.3);
glRotatef(90.0,0,1,0);
gluCylinder(t,0.02,0.03,.5,10,10);
glPopMatrix();
//********************WHEEL*********************************************
glColor3f(0.7,0.7,0.7);
glPushMatrix();
glBegin(GL_LINE_STRIP);
for(theta=0;theta<360;theta=theta+20)
{
glVertex3f(0.6,0.2,0.62);
glVertex3f(0.6+(0.08*(cos(((theta+angle)*3.14)/180))),0.2+(0.08*(sin(((theta+angle)*3.14)
/180))),0.62);
}
glEnd();
glBegin(GL_LINE_STRIP);
for(theta=0;theta<360;theta=theta+20)
{
glVertex3f(0.6,0.2,0.18);
glVertex3f(0.6+(0.08*(cos(((theta+angle)*3.14)/180))),0.2+(0.08*(sin(((theta+angle)*3.14)
/180))),0.18);
}
glEnd();
glBegin(GL_LINE_STRIP);
for(theta=0;theta<360;theta=theta+20)
{
glVertex3f(1.7,0.2,0.18);
glVertex3f(1.7+(0.08*(cos(((theta+angle)*3.14)/180))),0.2+(0.08*(sin(((theta+angle)*3.14)
/180))),0.18);
}
glEnd();
glBegin(GL_LINE_STRIP);
for(theta=0;theta<360;theta=theta+20)
{
glVertex3f(1.7,0.2,0.62);
glVertex3f(1.7+(0.08*(cos(((theta+angle)*3.14)/180))),0.2+(0.08*(sin(((theta+angle)*3.14)
/180))),0.62);
}
glEnd();
glTranslatef(0.6,0.2,0.6);
glColor3f(0,0,0);
glutSolidTorus(0.025,0.07,10,25);
glTranslatef(0,0,-0.4);
glutSolidTorus(0.025,0.07,10,25);
glTranslatef(1.1,0,0);
glutSolidTorus(0.025,0.07,10,25);
glTranslatef(0,0,0.4);
glutSolidTorus(0.025,0.07,10,25);
glPopMatrix();
//*************************************************************
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glutPostRedisplay();
glutSwapBuffers();
}
}
case 'y':
yangle += 5.0;
glutPostRedisplay();
break;
case 'Y':
yangle -= 5.0;
glutPostRedisplay();
break;
case 'z':
zangle += 5.0;
glutPostRedisplay();
break;
case 'Z':
zangle -= 5.0;
glutPostRedisplay();
break;
case 'U':
yt -= 0.2; /* Move down */
glutPostRedisplay();
break;
case 'F':
zt -= 0.2; /* Move away */
glutPostRedisplay();
break;
case 's':zs+=.2;
glutPostRedisplay();
break;
case 'S':zs-=0.2;
glutPostRedisplay();
break;
case 'a':ys+=.2;
glutPostRedisplay();
break;
case 'A':ys-=0.2;
glutPostRedisplay();
break;
case 'q':xs+=.2;
glutPostRedisplay();
break;
case 'Q':xs-=0.2;
glutPostRedisplay();
break;
default:
break;
}
case GLUT_KEY_LEFT:
if(!wheelflag)
xt -= 0.2;
if(wheelflag)
{
angle+=5;
xw-=0.2;
}
glutPostRedisplay();
break;
}
}
}
if(id ==2)
{
flag1=1;
flag2=0;
wheelflag=0;
xangle += 5.0;
glutPostRedisplay();
}
if(id==3)
{
flag2=1;
wheelflag=0;
xangle += 5.0;
glutPostRedisplay();
}
if (id==4)
{
wheelflag=1;
glutPostRedisplay();
}
if (id==5)
{
if(day)
{
if(light)
{
count++;
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
light=0;
}
else
{
count--;
light=1;
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
glutPostRedisplay();
}
else
{
aflag=0;
day=0;
glClearColor(0.1,0.1,0.1,0);
GLfloat fogcolour[4]={0.0,0.0,0.0,1.0};
glutPostRedisplay();
}
}
if(id==12)
{
aflag=1;
day=1;
glClearColor(1,1,1,1);
glDisable(GL_FOG);
glutPostRedisplay();
}
if(id==13)
{
aflag=0;
day=0;
flag2=2;
glClearColor(0.1,0.1,0.1,0);
GLfloat fogcolour[4]={0.0,0.0,0.0,1.0};
glutPostRedisplay();
}
}
}
if(id ==7)
{
r=0.8;
b=g=0;
glutPostRedisplay();
}
if(id==8)
{
g=1;
r=b=0;
glutPostRedisplay();
}
if (id==9)
{
r=b=g=0;
glutPostRedisplay();
}
if(id==10)
{
b=0;
r=g=1;
glutPostRedisplay();
}
if(id==11)
{
b=r=g=.7;
glutPostRedisplay();
}
//*************************** Main
***************************************************************
glutReshapeFunc(myreshape);
glutDisplayFunc(DrawGLScene); /* Function to do all our OpenGL drawing. */
glutReshapeFunc(ReSizeGLScene);
glutKeyboardFunc(NormalKey); /*Normal key is pressed */
glutSpecialFunc( SpecialKeyFunc );
InitGL(Xsize,Ysize);
int submenu=glutCreateMenu(colorMenu);
glutAddMenuEntry("blue", 6);
glutAddMenuEntry("red", 7);
glutAddMenuEntry("green",8);
glutAddMenuEntry("black",9);
glutAddMenuEntry("yellow",10);
glutAddMenuEntry("grey",11);
glutCreateMenu(myMenu);
glutAddMenuEntry("car model mode", 1);
glutAddMenuEntry("car driving mode", 2);
glutAddMenuEntry("fog effect",3);
glutAddMenuEntry("wheel effect",4);
glutAddMenuEntry("toggle light",5);
glutAddSubMenu("car colors",submenu);
glutAddMenuEntry("daymode",12);
glutAddMenuEntry("Night mode",13);
glutAttachMenu(GLUT_RIGHT_BUTTON);
/* Now drop into the event loop from which we never return */
CHAPTER 5
TESTING AND SNAPSHOTS
5.1 Testing
Testing is the process of executing a program to find the errors. A good test has the high
probability of finding a yet undiscovered error. A test is vital to the success of the system.
System test makes a logical assumption that if all parts of the system are correct, then goal
will be successfully achieved.
Car Model Mode This places the car Car is placed against
against a plain A plain background
background which is Which helps to view Success
helpful in viewing the the car model
car model
• Integration Testing
• System Testing
Unit Testing
Integration
System
While white box testing is applicable at the unit, integration and system levels of the
software testing process, it is typically applied to the unit. While it normally it
Normally tests paths within a unit, it also tests paths between units during integration, and
between subsystems during a system level test.
At key stages, testing was done to check the integrity of the project. The components tested
were: Initially, when dynamic memory allocations were being used, the code was
thoroughly tested for memory leaks. However, to minimize risk of leaks, all memory
allocations were converted to static.
As part of general testing the project has been tested for free from bugs and errors to
provide maximum efficiency and also traced through every function calls minutely for
any possible errors in the function. Errors found were successfully corrected
5.2 SNAPSHOTS
This type of display is obtained when the car model mode is chosen from the menu.
By default it will be in model mode.The car can be transformed and several effects can be
added to it with the use of keyboard and mouse.
This is the display obtained when the right mouse button is pressed and menus are viewed.
Here the car colors menu is chosen and a submenu called yellow is chosen. Hence the car
turned to yellow. Various options in the menu can be viewed in the above figure.
The car is amidst white fog. This effect comes into picture when the fog effects menu is
chosen.The entire screen is covered with white fog.
When the wheel effect is chosen from the menu, objects resembling milestones are added
to the display. When the car is tried to move with this effect, only the wheels of the car
moves and the milestones move, giving the effect of a car moving with a high speed.
The car is chosen to be displayed in the dawn through the menu provided. It can be
switched back to day mode.