Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Cgfull

Download as pdf or txt
Download as pdf or txt
You are on page 1of 58

CHAPTER 1

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.

1.1 Overview of Project


A car is a useful means of transportation from one place to another place. Development in
the field of science and technology led to the discovery of car which helped the mankind in
various ways. Since many years the automobiles have been subjected to continuous
evolution and hence a variety of car models with each one having its own features, shape
and size exist today. This is an approach to simulate the working of one such model of a car.
The car used here is a 3D object with simple features. One can either view the car model or
enter into the driving mode. In the former case, the car is placed against a plain background
whereas in the latter case, it is placed on a road having greenery in the background. The car
can be moved to and forth, rotated about the three principle axes and can be changed in
terms of size and color. Along with the above features the fog and wheel effects can also be
imposed on the car. The car can be viewed either in the day mode or in the night mode. A
uniform lighting effect is also included, however it is left to the user to enable or disable
lighting. Also, the car can be zoomed in or zoomed out. All these actions can be performed
by using the menu provided

1.2 Problem Statement


The problem is mainly concerned with modelling a car and highlighting some of the
common features of a car. The car is subjected to many OpenGL transformations to bring
out unique effects on the car. 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 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.

1.3 About OpenGL


OpenGL is a software interface to graphics hardware. This interface consists of about 150
distinct commands that is used to specify the objects and operations needed to produce
interactive three-dimensional applications.
OpenGL (Open Graphics Library) is a standard specification defining a cross-language,
cross-platform API for writing applications that produce 2D and 3D computer graphics the
interface consists of over 250 different function calls which can be used to draw complex
three-dimensional scenes from simple primitives. OpenGL was developed by Silicon
Graphics Inc. (SGI) in 1992 and is widely used in CAD, virtual reality, scientific
visualization, information visualization, and flight simulation.

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, user
must work through whatever windowing system controls the particular hardware that the
user is using.
OpenGL doesn't provide high-level commands for describing models of three- dimensional
objects. A sophisticated library that provides these features could certainly be built on top
of OpenGL. The OpenGL Utility Library (GLU) provides many of the modeling features.
OpenGL serves two main purposes:

• To hide the complexities of interfacing with different 3D accelerators, by presenting


the programmer with a single, uniform API.

• To hide the differing capabilities of hardware platforms, by requiring that all


implementations support the full OpenGL feature set (using software emulation if
necessary).
OpenGL's basic operation is to accept primitives such as points, lines, polygons, and
convert them into pixels. This is done by a graphics pipeline known as the OpenGL state
machine.

Department of CSE, HMSIT 2024 Page 2


CHAPTER 1 INTRODUCTION
The colour plate gives an idea of the kinds of things that can be done with the OpenGL
graphics system. The following list briefly describes the major graphics operations which
OpenGL performs to render an image on the screen.

• Construct shapes from geometric primitives, thereby creating mathematical


descriptions of objects. (OpenGL considers points, lines, polygons, images, and
bitmaps to be primitives.)

• 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.

• Convert the mathematical description of objects and their associated color


information to pixels on the screen. This process is called rasterization.

1.3.1 OpenGL Command Syntax


OpenGL commands use the prefix gland initial capital letters for each word making up the
command name (recall clearcole(), for example).

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.

1.3.2 OpenGL as a State Machine

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

Department of CSE, HMSIT 2024 Page 3


CHAPTER 1 INTRODUCTION
glDisable (). Each state variable or mode has a default value, and at any point the user can
query the system for each variable's current value.

1.3.3 OpenGL Rendering Pipeline

Figure 1.1: Order of Operations

Most implementations of OpenGL have a similar order of operations, a series of processing


stages called the OpenGL rendering pipeline. Given below are the key stages in the OpenGL
rendering pipeline.

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

Department of CSE, HMSIT 2024 Page 4


CHAPTER 1 INTRODUCTION
or polygon is clipped. The results of this stage are complete geometric primitives, which are
the transformed and clipped vertices with related color, depth, and sometimes
texturecoordinate values and guidelines for the rasterization step.

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.

1.3.4 OpenGL - Related Libraries


OpenGL provides a powerful but primitive set of rendering commands, and all higherlevel
drawing must be done in terms of these commands. Also, OpenGL programs have to use
the underlying mechanisms of the windowing system. A number of libraries exist to allow
the user to simplify the programming tasks, including the following:
The OpenGL Utility Toolkit (GLUT) is a programming interface with ANSI C and
FORTRAN bindings for writing window system independent OpenGL programs. The
toolkit supports the following functionality:

• Multiple windows for OpenGL rendering.

• Callback driven event processing.

• Sophisticated input devices.

Department of CSE, HMSIT 2024 Page 5


CHAPTER 1 INTRODUCTION
• An “idle” routine and timers.

• A simple, cascading pop-up menu facility.

• Utility routines to generate various solid and wire frame objects.

• Support for bitmap and stroke fonts.

• Miscellaneous window management functions, including managing


overlays.

Department of CSE, HMSIT 2024 Page 6


CHAPTER 2

REQUIREMENT SPECIFICATIONS

A requirements specification is a description of a software system to be developed, laying


out functional and non-functional requirements, and may include a set of use cases that
describe interactions the users will have with the software.

2.1 Requirements of the project


A graphics package that attracts the attention of the viewers is to be implemented. The

package should provide a platform for user to perform animation.

2.2 Resource Requirements


The requirement analysis phase of the project can be classified into:

. Hardware Requirements

• Software Requirements

• Functional Requirements

• Non-Functional Requirements

2.2.1 Software Requirements


This document will outline the software design and specification of our application. The
application is a Windows based .Net implementation with OpenGL. Our main UI will be
developed in C#, which is a .Net language. This application will allow viewing of GDS II
files, assignment of Color and Transparency to layers within the VLSI object, as well as
printing of the rendered object. There will be the ability to save these color/transparency
palettes for a given GDS file as well as the foundry used to create the file. These palettes
can then be used with future GDS files to save time assigning colors/transparencies to
layers.
Characteristics required of the interface between the software product and each of the

hardware components

PAGE 7
CHAPTER 2 REQUIREMENT SPECIFICATIONS

Any mouse and keyboard that works with Win Forms

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.

OpenGL libraries for required are

• 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.

• Processor: Intel® Pentium 4 CPU

• Hard disk Capacity: 80 GB

• RAM: 1 GB

• CPU Speed: 2.9 GHz

• Keyboard: Standard

• Mouse: Standard

Department of CSE, HMSIT 2024 Page 8


CHAPTER 2 REQUIREMENT SPECIFICATIONS

Visual Studio Hardware Requirements


Some specific hardware requirements are needed for Visual Studio 2010. They can be listed
as:

Requirement Professional

Processor 1.6 GHz processor or higher

RAM
384 MB of RAM or more (768 MB of RAM or

more for Windows Vista)

Available Without MSDN:


Hard 2.2 GB of available space
Disk required
Space on system drive

With MSDN:

3.8 GB of available space


required

on installation drive with a


full installation of

MSDN

Department of CSE, HMSIT 2024 Page 9


CHAPTER 2 REQUIREMENT SPECIFICATIONS

Operating Visual Studio 2010can be installed on the


following operating system:
System
Windows® XP (x86 &x64) with Service Pack

2 or later all editions except Starter Edition

Windows Server 2003 R2 (x86 and x64)

Video 1024 X 768, High Color 16-bit

Mouse Microsoft mouse or compatible pointing device

Table 2.1: Hardware Requirements for Visual Studio 2010

• 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.

Department of CSE, HMSIT 2024 Page 10


CHAPTER 2 REQUIREMENT SPECIFICATIONS

• The type of media provided with the product determines whether a CD-ROM
drive or DVD-ROM drive is required.

2.2.3 Functional Requirements


These are the statements of services the system should provide, how the system should
react to particular inputs and how the system should behave in particular situations. In
some cases, the functional requirements may also explicitly state what the system should
not do.

2.2.4 Non-Functional Requirements


These are the requirements that are not directly concerned with the specific functions
delivered by the system. They may relate to emergent system properties such as reliability,
response time and so on.

• Only after selecting a different primitive, rotation speed, direction of rotation,

background will the changes be observed. Hence this project is reliable.

• 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.

Department of CSE, HMSIT 2024 Page 11


CHAPTER 2 REQUIREMENT SPECIFICATIONS

Department of CSE, HMSIT 2024 Page 12


CHAPTER 3 DESIGN PHASE

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

main( argc, * argv[] )

{
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 ()

Department of CSE HMS 2024 Page 11


CHAPTER 3 DESIGN PHASE

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
()
}

Department of CSE HMS 2024 Page 12


CHAPTER 3 DESIGN PHASE

Step 6: The display function to create the Help screen. display1(

{
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

Department of CSE HMS 2024 Page 13


CHAPTER 3 DESIGN PHASE

wheels of car drawn using glutSolidTorous() if car is in driving mode


then
{
Draw green surroundings, long road, and median
}
glutSwapBuffers( );
} //end ofelse
} //end of DrawGLScene( )
Step 8: The action taken when a Normal key is pressed. NormalKey
(key, x, y)
{
ifkey=ESCAPE then exit(0) if key=’ ‘ then view=1 if key=’x/X’ then xangle++
/xangle-- respectively // Rotate about x axis if key=’y/Y’ then yangle++/yangle--
respectively // Rotate about y axis if key=’z/Z’ then zangle++/zangle--
respectively //Rotate about z axis if key=’u/U’ thenyt++/yt-- //move camera up
and down respectively if key=’f/F’ thenzt++/zt++ //move camera forward and
away respectively ifkey=’s/S’ then zs++/zs-- //scale along z axis if key=’a/A’
thenys++/ys-- //scale along y axis
if key=’q/Q’ thenxs++/xs-- //scale along x axis
}//End of Normal key
Step 9: The action taken when a special key is pressed.
SpecialkeyFunc(key,x, y)
{
if key=GLUT_RIGHT_KEY then xt++ if key=GLUT_LEFT_KEY
thenxt- -
}
Step 10: The actions performed by each menu entry identified by id. myMenu(
id )
{
if id=’ car model mode’ then
{

Department of CSE HMS 2024 Page 14


CHAPTER 3 DESIGN PHASE

Draw car against plain back ground


}

If id= ‘car driving mode’ then


{
Draw car against the road with greenery around
} if id=’fog effect’
then
{

Enable white color fog


}

if id=’wheel effect ‘ then


{
Emphasize fast movement by adding mile stones along the Road

If id=’ toggle ‘ then

{
Enable lighting
effects } if id=’day
mode’ then
{

Set back ground white

If id=‘ night mode’ then

Enable black fog

Department of CSE HMS 2024 Page 15


CHAPTER 3 DESIGN PHASE

3.2 Data flow Diagram:


A flowchart is a common type of chart that represents an algorithm or process showing the
steps as boxes of various kinds, and their order by connecting these with arrows. Flowcharts
are used in analyzing, designing, documenting or managing a process or program in various
fields
Flowcharts used to be a popular means for describing computer algorithms. They
are still used for this purpose; modern techniques such as UML activity diagrams can be
considered to be extensions of the flowchart.
However, their popularity decreased when, in the 1970s, interactive computer
terminals and third-generation programming languages became the common tools of the
trade, since algorithms can be expressed much more concisely and readably as source code
in such a language. Often, pseudo-code is used, which uses the common idioms of such
languages without strictly adhering to the details of a particular one.
There are many different types of flowcharts. On the one hand there are different
types for different users, such as analysts, designers, engineers, managers, or programmers.
On the other hand those flowcharts can represent different types of objects.
Sterneckert (2003) divides four more general types of flowcharts:
• Document flowcharts, showing a document flow through system

• Data flowcharts, showing data flows in a system

• System flowcharts showing controls at a physical or resource level

• Program flowchart, showing the controls in a program within a system

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.

Department of CSE, HMS 2024 Page 16


CHAPTER 3 DESIGN PHASE

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

Diagram Figure 3.2:Data flow.

The above Figure 3.2 shows the Data flow Diagram .The processing of different operations
in this project.

Department of CSE, HMS 2024 Page 17


CHAPTER 3 DESIGN PHASE

Department of CSE, HMS 2024 Page 18


CHAPTER 4

IMPLEMENTATION

The implementation stage of this model involves the following phases.

• Implementation of OpenGL built in functions. •


User defined function Implementation.

4.1 Implementation of OpenGL Built In Functions


2. glutInitDisplayMode( )
glutInitDisplayMode sets the initial display mode.

Usage: void glutInitDisplayMode (unsigned int mode);

Mode - Display mode, normally the bitwise OR-ing of GLUT display mode bit masks.

See values below:

GLUT_RGBA- Bit mask to select an RGBA mode window.

GLUT_RGB- An alias for GLUT_RGBA.

GLUT_SINGLE-Bit mask to select a single buffered window.

GLUT_DOUBLE or GLUT_SINGLE are specified.

GLUT_DOUBLE-Bit mask to select a double buffered window. This overrides


GLUT_SINGLE if it is also specified.
CHAPTER 4 IMPLEMENTATION

Department of CSE,HMS 2024 Page 17 GLUT_DEPTH- Bit mask to select a window


with a depth buffer.

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

Name - ASCII character string for use as window name.

Description:glutCreateWindow creates a top-level window. The name will be provided to


the window system as the window's name. The intent is that the window system will labelthe
window with the name. Implicitly, the current window is set to the newly created window.
Each created window has a unique associated OpenGL context.
4.glutDisplayFunc( )
glutDisplayFunc sets the display callback for the current window.
Usage: void glutDisplayFunc(void (*func)(void)); Func- The
new display callback function.
Description:glutDisplayFunc sets the display callback for the current window. When
GLUT determines that the normal plane for the window needs to be redisplayed, the display
callback for the window is called. Before the callback, the current window is set to the
window needing to be redisplayed and the layer in use is set to the normal plane. The display
callback is called with no parameters. The entire normal plane region should be redisplayed
in response to the callback.
4. glutKeyboardFunc( )
glutKeyboardFunc sets the keyboard callback for the current window. Usage: void
glutKeyboardFunc(void (*func)(unsigned char key,int x, int y)); Func- The new
keyboard callback function.
Description: glutKeyboardFunc sets the keyboard callback for the current window. When
a user types into the window, each key press generating an ASCII character will generate a
keyboard callback. The key callback parameter is the generated ASCII character. The and

Department of CSE,HMS 2024 Page 18


CHAPTER 4 IMPLEMENTATION

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.

7. glutPostRedisplay( ) glutPostRedisplay marks the current windowas


needing to be redisplayed.
Usage: void glutPostRedisplay(void);
Description: Mark the normal plane of current windowas needing to be redisplayed. The
next iteration through glutMainLoop, the window’s display callback will be called
toredisplay the window’s normal plane. Multiple calls to glutPostRedisplay before the next
display callback opportunity generates only a single redisplay callback.
textureNameis the ID of the texture (which is acquired via glGenTextures()..

4.2 Implementation of User Defined Functions:

Department of CSE,HMS 2024 Page 19


CHAPTER 4 IMPLEMENTATION

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

Department of CSE,HMS 2024 Page 20


CHAPTER 4 IMPLEMENTATION

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

glutInitWindowPosition, glutInitWindowSize Functions


glutInitWindowPosition and glutInitWindowSize set the initial window position and size
respectively.
SYNTAX: void glutInitWindowSize(int width, int height); voidglutInitWindowPosition(int
x, int y);

glutCreateWindow Function
glutCreateWindow creates a top-level window with the name contained in the string
‘title’.

Department of CSE,HMS 2024 Page 21


CHAPTER 4 IMPLEMENTATION

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

Department of CSE,HMS 2024 Page 22


CHAPTER 4 IMPLEMENTATION

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

Department of CSE,HMS 2024 Page 23


CHAPTER 4 IMPLEMENTATION

/* The main drawing function

In here we put all the OpenGL and calls to routines which manipulate
the OpenGL state and environment.

This is the function which will be called when a "redisplay" is requested.


*/

void display_string(int x, int y, char *string, int font)


{
int len,i;
glColor3f(0.8,0.52,1.0);
glRasterPos2f(x, y);
len = (int) strlen(string);
for (i = 0; i < len; i++) {
if(font==1)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,string[i]);
if(font==2)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,string[i]);
if(font==3)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,string[i]);
if(font==4)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10,string[i]);
}

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

Department of CSE,HMS 2024 Page 24


CHAPTER 4 IMPLEMENTATION

display_string(10,280,"U-F FOR CAMERA VIEW SETTINGS",3);


display_string(10,250,"USE LEFT ARROW(<-) AND RIGHT ARROW(->) TO
MOVE CAR",3);
display_string(10,220,"ESCAPE TO EXIT",3);
display_string(250,150,"PRESS SPACE BAR TO ENTER",2);
glutPostRedisplay();
glutSwapBuffers();

GLvoid DrawGLScene()
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Clear The


Screen And The Depth Buffer */
if(view==0)
{
init();
display1();
}
else
{
if(count==1)
InitGL(Xsize,Ysize);
if(aflag==1)/* Initialize our window. */
glClearColor(1,1,1,1);
else
glClearColor(0.1,0.1,0.1,0);
glPushMatrix();
glLoadIdentity();
glTranslatef(-1.0,0.0,-3.5);
glRotatef(xangle,1.0,0.0,0.0);
glRotatef(yangle,0.0,1.0,0.0);
glRotatef(zangle,0.0,0.0,1.0);
glTranslatef(xt,yt,zt);
glScalef(xs,ys,zs);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

if(flag2==1)
{
GLfloat fogcolour[4]={1.0,1.0,1.0,1.0};

Department of CSE,HMS 2024 Page 25


CHAPTER 4 IMPLEMENTATION

glFogfv(GL_FOG_COLOR,fogcolour); /* Define the fog colour */


glFogf(GL_FOG_DENSITY,0.1); /* How dense */
glFogi(GL_FOG_MODE,GL_EXP); /* exponential decay */
glFogf(GL_FOG_START,3.0); /* Where wwe start fogging */
glFogf(GL_FOG_END,100.0); /* end */
glHint(GL_FOG_HINT, GL_FASTEST); /* compute per vertex */
glEnable(GL_FOG);/* ENABLE */
}
if(flag2==0)
{
glDisable(GL_FOG);
}

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

glBegin(GL_QUADS); /* OBJECT MODULE*/

/* top of cube*/

Department of CSE,HMS 2024 Page 26


CHAPTER 4 IMPLEMENTATION

//************************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******************************

Department of CSE,HMS 2024 Page 27


CHAPTER 4 IMPLEMENTATION

glColor3f(r,g,b); /* Set The Color To Blue*/


glVertex3f( 1.8, 0.5,0.6);
glVertex3f(1.8, 0.5,0.2);
glVertex3f(2.1, 0.4, 0.2);
glVertex3f(2.1,0.4,0.6);

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

Department of CSE,HMS 2024 Page 28


CHAPTER 4 IMPLEMENTATION

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

glVertex3f( 0.75, 0.65,0.2);


glVertex3f(0.75, 0.63,0.2); //line strip
glVertex3f(1.7, 0.63, 0.2);
glVertex3f( 1.7,0.65,0.2);

glVertex3f( 0.75, 0.65,0.6);


glVertex3f(0.75, 0.63,0.6); //line strip
glVertex3f(1.7, 0.63, 0.6);
glVertex3f( 1.7,0.65,0.6);

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

Department of CSE,HMS 2024 Page 29


CHAPTER 4 IMPLEMENTATION

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

//*****************************road and surrounding


development***********************************
if(flag1)
{

Department of CSE,HMS 2024 Page 30


CHAPTER 4 IMPLEMENTATION

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

Department of CSE,HMS 2024 Page 31


CHAPTER 4 IMPLEMENTATION

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

glVertex3f( 0.6, 0.5,0.2);


glVertex3f( 0.7,0.65,0.2); //tri front window
glVertex3f(0.7,0.5,0.2);

glVertex3f( 1.7, 0.65,0.2);


glVertex3f( 1.8,0.5,0.2); //tri back window
glVertex3f( 1.7,0.5,0.2);

glVertex3f( 1.7, 0.65,0.6);


glVertex3f( 1.8,0.5,0.6); //tri back window
glVertex3f(1.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);

Department of CSE,HMS 2024 Page 32


CHAPTER 4 IMPLEMENTATION

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

Department of CSE,HMS 2024 Page 33


CHAPTER 4 IMPLEMENTATION

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

/* The function called whenever a "normal" key is pressed. */


void NormalKey(GLubyte key, GLint x, GLint y)
{
switch ( key ) {
case ESCAPE : printf("escape pressed. exit.\n");
glutDestroyWindow(window); /* Kill our window */
exit(0);
break;

case ' ':view=1;


DrawGLScene();
break;

case 'x': xangle += 5.0;


glutPostRedisplay();
break;

case 'X':xangle -= 5.0;


glutPostRedisplay();
break;

Department of CSE,HMS 2024 Page 34


CHAPTER 4 IMPLEMENTATION

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': /* Move up */


yt += 0.2;
glutPostRedisplay();
break;

case 'U':
yt -= 0.2; /* Move down */
glutPostRedisplay();
break;

case 'f': /* Move forward */


zt += 0.2;
glutPostRedisplay();
break;

case 'F':
zt -= 0.2; /* Move away */
glutPostRedisplay();
break;

case 's':zs+=.2;
glutPostRedisplay();
break;

Department of CSE,HMS 2024 Page 35


CHAPTER 4 IMPLEMENTATION

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

static void SpecialKeyFunc( int Key, int x, int y )


{
switch ( Key ) {
case GLUT_KEY_RIGHT:
if(!wheelflag)
xt += 0.2;
if(wheelflag)
{
angle+=5;
xw+=0.2;
}
glutPostRedisplay();
break;

case GLUT_KEY_LEFT:
if(!wheelflag)
xt -= 0.2;

Department of CSE,HMS 2024 Page 36


CHAPTER 4 IMPLEMENTATION

if(wheelflag)
{
angle+=5;
xw-=0.2;
}
glutPostRedisplay();
break;
}
}

void myMenu(int id)


{
if (id==1)
{
flag1=0;
wheelflag=0;
glutPostRedisplay();

}
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)
{

Department of CSE,HMS 2024 Page 37


CHAPTER 4 IMPLEMENTATION

if(light)
{
count++;
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
light=0;
}
else
{
count--;
light=1;
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
glutPostRedisplay();
}
else
{

if(nml==0 && flag2==2)


{
flag2=0;
nml=1;
}
else
{
flag2=2;
nml=0;

aflag=0;
day=0;

glClearColor(0.1,0.1,0.1,0);
GLfloat fogcolour[4]={0.0,0.0,0.0,1.0};

glFogfv(GL_FOG_COLOR,fogcolour); /* Define the fog colour */


glFogf(GL_FOG_DENSITY,0.5); /* How dense */
glFogi(GL_FOG_MODE,GL_EXP); /* exponential decay */
/* end */
glHint(GL_FOG_HINT, GL_FASTEST); /* compute per vertex */
glEnable(GL_FOG);

glutPostRedisplay();

Department of CSE,HMS 2024 Page 38


CHAPTER 4 IMPLEMENTATION

}
}

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

glFogfv(GL_FOG_COLOR,fogcolour); /* Define the fog colour */


glFogf(GL_FOG_DENSITY,0.5); /* How dense */
glFogi(GL_FOG_MODE,GL_EXP); /* exponential decay */
/* end */
glHint(GL_FOG_HINT, GL_FASTEST); /* compute per vertex */
glEnable(GL_FOG);

glutPostRedisplay();
}
}

void colorMenu(int id)


{
if (id==6)
{
r=g=0;
b=1;
glutPostRedisplay();

}
if(id ==7)

Department of CSE,HMS 2024 Page 39


CHAPTER 4 IMPLEMENTATION

{
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();
}

void myreshape(int w,int h)


{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,-
10.0,10.0);
else
glOrtho(-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)w/(GLfloat)h,-2.0,2.0,-
10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
}

Department of CSE,HMS 2024 Page 40


CHAPTER 4 IMPLEMENTATION

//*************************** Main
***************************************************************

int main(int argc, char **argv)


{

/* Initialisation and window creation */

glutInit(&argc, argv); /* Initialize GLUT state. */

glutInitDisplayMode(GLUT_RGBA | /* RGB and Alpha */


GLUT_DOUBLE| /* double buffer */
GLUT_DEPTH); /* Z buffer (depth) */

glutInitWindowSize(Xsize,Ysize); /* set initial window size. */


glutInitWindowPosition(0,0); /* upper left corner of the screen. */

glutCreateWindow("3D CAR WITH TRANSFORMATIONS"); /* Open a window with a


title. */

/* Now register the various callback functions */

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

Department of CSE,HMS 2024 Page 41


CHAPTER 4 IMPLEMENTATION

glutAddMenuEntry("daymode",12);
glutAddMenuEntry("Night mode",13);
glutAttachMenu(GLUT_RIGHT_BUTTON);

/* Now drop into the event loop from which we never return */

glutMainLoop(); /* Start Event Processing Engine. */


return 1;
}

Department of CSE,HMS 2024 Page 42


CHAPTER 5 TESTING AND SNAPSHOTS

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.

Input Expected Output Output Status

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

Car Driving Mode Car is placed on the Car is placed on the


road having greenery road having greenery Success
on its sides on its sides

Fod Effect The entire display is The entire display is


covered with fog covered with fog Success

Wheel Effect The Effects on the The Effects on the


wheel are shown on the Wheel are shown on Success
Display of car model
The display
Car Colors Various colors for the Various colors for the
car can be chosen car can be chosen Success

Day and Night Mode Entire display changes Entire display


accordingly changes accordingly Success

Table 5.1: Testing

Department of CSE,HMS 2024 Page43


CHAPTER 5 TESTING AND SNAPSHOTS

5.1.1 Types of Testing


• Unit Testing

• Integration Testing

• System Testing

5.1.2 Unit Testing


Here we test the movement of each bird separately .Step by step testing is done to check
whether all the birds are placed at the correct positions, to check whether they are translated
properly and whether the target disappears or changes color when it is hit.

5.1.3 Integration Testing


All the patterns are called together and we add mouse functions and check whether it is
executing successfully, check whether the mouse input can be taken successfully are
displayed correctly.
Black box testing takes an external perspective of the test object to derive test cases.
These tests can be functional or non-functional, though usually functional. The test designer
selects valid and invalid inputs and determines the correct output. There is no knowledge
of the test object's internal structure.
This method of test design is applicable to all levels of software testing: unit,
integration, functional testing, system and acceptance. The higher the level, and hence the
bigger and more complex the box, the more one is forced to use black box testing to
simplify. While this method can uncover unimplemented parts of the specification, one
cannot be sure that all existent paths are tested. Bottom-Up Testing is an approach to
integration testing where the lowest level components are tested first, then used to facilitate
the testing of higher level components. The process is repeated until the component at the
top of the hierarchy is tested.
This project has been tested for its working and is found the requirements as mentioned.
The input device used is mouse which has been tested for correct operation.

Department of CSE,HMS 2024 Page44


CHAPTER 5 TESTING AND SNAPSHOTS

5.1.4 System Testing


The different components are integrated to make up the entire system. The testing process
is concerned with finding errors, which result from unanticipated interactions between the
different components. It is also concerned with validating that the system meets its
functional and non – functional requirements.
This testing procedure was carried out iteratively with addition of every new
component. The initial component was the creation of bird. This was system – tested with
the addition of translation of the bird. These two were retested with the case where the
bird hits the target and the target successfully disappears

Unit Testing

Integration

System

Figure 5.1: Testing Process

5.1.5 White Box Testing:


White Box Testing uses an internal perspective of the system to design test cases based on
internal structure. It requires programming skills to identify all paths through the software.
The tester chooses test case inputs to exercise paths through code and determines the
appropriate outputs. Since the tests are based on the actual implementation, implementation
change would require that the tests will need to change too.

Department of CSE,HMS 2024 Page45


CHAPTER 5 TESTING AND SNAPSHOTS

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.

5.1.6 Black box testing:


System testing is testing conducted on a complete, integrated system to evaluate the
system's compliance with its specified requirements. System testing falls within the scope
of black box testing, and as such, should require no knowledge of the inner design of the
code or logic.
Black box testing takes an external perspective of test object to derive test cases. These
tests can be functional or non-functional, through usually functional. The test designer
selects the valid and invalid inputs and determines the correct output. There is no
knowledge of the test objects internal structure. This method can be applied different types
of testing: unit, integration, functional testing, system and acceptance.

Department of CSE,HMS 2024 Page46


CHAPTER 5 TESTING AND SNAPSHOTS

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

Department of CSE,HMS 2024 Page47


CHAPTER 5 TESTING AND SNAPSHOTS

5.2 SNAPSHOTS

Figure 5.1 The Help Window.


The Help window displays the details about the usage of various keys and mouse button in
this project. It is immediately displayed when the program begins its execution.

Department of CSE,HMS 2024 Page48


CHAPTER 5 TESTING AND SNAPSHOTS

Figure 5.2 The car in model mode.

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.

Department of CSE,HMS 2024 Page49


CHAPTER 5 TESTING AND SNAPSHOTS

Figure 5.3 Car in driving mode.


This is the display seen when driving mode is selected from the menu. All the effects
seen in car model mode can also be viewed in this mode by pressing appropriate keys and
options in menu.

Department of CSE,HMS 2024 Page50


CHAPTER 5 TESTING AND SNAPSHOTS

Figure 5.4 The display with menu.

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.

Department of CSE,HMS 2024 Page51


CHAPTER 5 TESTING AND SNAPSHOTS

Figure 5.5 Car with fog effects.

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.

Department of CSE,HMS 2024 Page52


CHAPTER 5 TESTING AND SNAPSHOTS

Figure 5.6 Car with wheel effects.

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.

Department of CSE,HMS 2024 Page53


CHAPTER 5 TESTING AND SNAPSHOTS

Figure 5.7 Car in the night mode.

The car is chosen to be displayed in the dawn through the menu provided. It can be
switched back to day mode.

Department of CSE,HMS 2024 Page54

You might also like