You are on page 1of 24

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

BELAGAVI-590018, KARNATAKA

A Mini Project Report


On

“Graphical simulation of a Ship using Open GL”


Submitted in Partial Fulfillment of the Requirement for
“CG Laboratory with Mini Project -VI Semester”
For the Award of Degree

BACHELOR OF ENGINEERING
IN

COMPUTER SCIENCE & ENGINEERING


Submitted By:
Anish Bhat (1SG19CS007)
Abhijith Y L (1SG19CS002)
Under the Guidance of:
Prof. Chaithra Prof. Shwetha B N
Associate Professor Assistant Professor

Department of Computer Science and Engineering


SAPTHAGIRI COLLEGE OF ENGINEERING
Accredited by NBA
(Affiliated to Visvesvaraya Technological University, Belagavi& Approved by AICTE, New Delhi.)
ISO 9001-2015 & 14001-2015 Certified, Accredited by NAAC with ‘A’ Grade,
#14/5, Chikkasandra, Hesaraghatta Main Road,
Bengaluru-560057
2021-2022
SAPTHAGIRI COLLEGE OF ENGINEERING
Affiliated to Visvesvaraya Technological University, Belagavi& Approved by AICTE, New Delhi.)
ISO 9001-2015 & 14001-2015 Certified, Accredited by NAAC with ‘A’ Grade
#14/5, Chikkasandra, Hesaraghatta Main Road,
Bengaluru-560057

Department of Computer Science and Engineering


Accredited by NBA

Certificate

This is to certify that the Mini Project Work entitled “Graphical simulation of a Ship using Open GL”
carried out by ANISH BHAT(1SG19CS007) and ABHIJITH Y L(1SG19CS002), bonafide students of
Sapthagiri College of Engineering, in partial fulfillment for the award of Bachelor of Engineering degree
in Computer Science and Engineering of Visvesvaraya Technological University, Belagavi during the
academic year 2021-2022. It is certified that all corrections/suggestions indicated have been incorporated in
the report. The project report has been approved as it satisfies the academic requirements in respect of CG
Laboratory with Mini Project (18CSL67) prescribed for the said Degree.

Signature of the Guide Signature of the Guide Signature of the HOD


Mrs. Chaithra Mrs. Swetha B.N Dr. Kamalakshi Naganna
Associate Professor Assistant Professor Professor& Head

EXTERNAL EXAMINATION

Name of the Examiners Signature with Date

1.___________________________ _________________________

2.___________________________ _________________________
ACKNOWLEDGEMENT

The satisfaction and euphoria that accompany the completion of any task would be incomplete
without the mention of the people who made it possible, whose constantguidance and encouragement
ground my efforts with success.

We consider it a privilege to express our gratitude and respect to all those who guided us in
completion of this project.

We are grateful to our Principal Dr. H Ramakrishna, Sapthagiri College of Engineering, who
patronized throughout our career & for the facilities provided to carry outthis work successfully.

It’s a great privilege to place on record our deep sense of gratitude to our beloved HOD Dr.
Kamalakshi Naganna of Computer Science & Engineering, who patronized throughout our career &
for the facilities provided to carry out this work successfully.

We are also grateful to our mini project Guides Prof. Chaithra, Associate Professor & Mrs.
Swetha B.N., Assistant Professor of CSE department for their invaluable support and guidance.

We would also like to thank the teaching and non-teaching staff members who have helped us
directly or indirectly during the project preparation.

Lastly but most importantly we would like thank our family and friends for their co- operation
and motivation to complete this project successfully.

ANISH BHAT (1SG19CS007)

ABHIJITH YADAV L (1SG19CS002)

I
ABSTRACT

This project demonstrates a simple simulation of a ship in different environments. Here the different
times of day are represented with different colors for background and lighting. We have also provided
a movement operation for the ship with an ability to shoot projectiles from any given position.

Here we use the keyboard as an input device. Keyboard events are generated when the mouse is
in the window and one of the keys is pressed or released. The GLUT function glutKeyboardFunc
is the callback for events generated by pressing the key. When it occurs the ASCII code for
the key that generated the event and the location of the mouse are returned. All the keyboard
callbacks are registered in a single callback function, such as the following:

glutKeyboardFunc(keyboard);
The callback is specified in GLUT by the following function call:
glutDisplayFunc(display);
It is invoked when GLUT determines that the window should be redisplayed.

II
TABLE OF CONTENTS

SL. NO. CHAPTERS PAGE No.


1. Introduction 1
1.1 Overview Of The Project 2
1.2 Aim Of The Project 3

2. Requirement Specification 4
2.1 Functional Requirements 4
2.2 Non-Functional Requirements 4
2.2.1 Dependability
2.2.2 Availability
2.2.3 Reliability
2.2.4 Safety
2.2.5 Security
2.3 Details Of The Software 5
2.3.1 Microsoft Visual C++
2.3.2 Opengl And Glut
2.4 Software Requirements 6
2.5 Hardware Requirements 6

3. Design 7

4. Implementation 9
4.1 User Defined Functions 9
4.2 Built In Functions 10

5. Testing 12

6. Snapshots 13

7. Conclusion 17

Bibliography 18

III
LIST OF FIGURES

Sl. No. Figure No. Title of figure Page No.

1 1.1 Library organization of OpenGL 2

2 3.1 Flow chart for simulation of Ship 7

3 6.1 Main Page 13

4 6.2 Initial Output Screen 13

5 6.3 Early Morning Screen 14

6 6.4 Morning Screen 14

7 6.5 Afternoon Screen 15

8 6.6 Evening Screen 15

9 6.7 Night Screen 16

10 6.8 Midnight Screen 16

IV
Graphical simulation of a Ship

CHAPTER 1
INTRODUCTION

The Computer Graphics is one of the most effective and commonly used methods to
communicate the processed information to the user. It displays the information in the form of graphics
objects such as pictures, charts, graphs and diagram instead of simple text.

In computer graphics, pictures or graphics objects are presented as a collection of discrete


picture elements called pixels. The pixel is the smallest addressable screen element.

Computer graphics today is largely interactive: The user controls the contents structure, and
appearance of objects and their displayed images by using input devices, such as a keyboard, mouse,
or touch-sensitive panel on the screen.

The image processing can be classified as


• Image enhancement.
• Pattern detection and recognition
• Scene analysis and computer vision.

The image enhancement deals with the improvement in the image quality by eliminating noise
or by increasing image contrast. Pattern detection and recognition deals with the detection and
clarification of standard patternsand finding deviations from these patterns .The optical character
recognition (OCR) technology is an practical example for pattern detection & recognition. Scene
analysis deals with the recognition and reconstruction of 3D model of scene from several 2D images.

The applications of computer graphics in some of the major areas are as follows
1. Display of information.
2. Design.
3. Simulation and Animation.
4. User interfaces.

Dept. of CSE, SCE Page 1


Graphical simulation of a Ship

Fig 1.1: Library organization of OpenGL

1.1 Overview of the project


Implementing certain technical concepts like transformation. To show that implementation of
bubble sort and selection sort graphically. Migration from text editor to OpenGL. Consists of array of
elements represented in the form of circles in random order. Sorting the randomized elements.
Displaying the elements that are being swapped.

The various concepts used in this application are as follows:


Menus:
OpenGL supports simple cascading pop-up menus. In this application simple pop-up menus
along with the submenu are used to provide a simple user interface. The menu will pop up by clicking
the right mouse button.

Blending:
The project uses blending to make objects appear transparent.

Transformations:
A transformation is a function that takes a point or vector and maps that point or vector into
another point or vector. In this application the transformation is used to make the plane to rotate in all
3 axis.

Bitmap Character:
OpenGL supports two kinds of texts: bitmap character and stroke character. Bitmap characters are
basically 2D font without thickness. In this application bitmap character is used to display the texts.

Dept. of CSE, SCE Page 2


Graphical simulation of a Ship

The main features of the project are as follows


➢ The application is user friendly, thereby it can be used by children and who do not know
computer in depth too.
➢ As provision for future development.
➢ It has many options of keyboard functions.
➢ It has a good visual effect.

1.2 Aim of the project


The project has been implemented in modules so as to make it user friendly i.e. if a code viewer
is finding trouble with a particular function it can go to a particular module and make corresponding
changes in it instead of searching in the program. Also it is more advantageous for future modifications
as when modifications are to be made instead of searching the whole program module search can be
useful as it decreases the time consumption.

Dept. of CSE, SCE Page 3


Graphical simulation of a Ship

CHAPTER 2
REQUIREMENT SPECIFICATION

A software requirement definition is an abstract description of the services which the system should
provide, and the constraints under which the system must operate. It should only specify the external
behavior of the system.

2.1 Functional requirements


In software engineering, a functional requirement defines a function of a software
system or its component. A function is described as a set of inputs, the behavior, and outputs (see also
software). Functional requirements may be calculations, technical details, data manipulation and
processing and other specific functionality that define what a system is supposed to accomplish.
Behavioral requirements describing all the cases where the system uses the functional requirements
are captured in use cases.

The various methods used in this project are as follows:-


❖ Display
The module draws the output on the screen and the functions in it.
❖ Menu
This module specifies the action corresponding to menu entry.
❖ Keyboard
The module specifies the action corresponding to the key board.
❖ Idle
This module is used to display the object more times using some delay t.
Displaying default screen with ship and plane.
Change screen depending on user input.

2.2 Non-functional requirements:


These are constraints on the services or functions offered by the system. They include timing
constraints, constraints on the development process and standards. Non-functional requirements often
apply to the system as a whole.

Dept. of CSE, SCE Page 4


Graphical simulation of a Ship

Non-Functional Requirements are as follows:-


2.2.1 Dependability:
The dependability of a computer system is a property of the system that equates to its
trustworthiness. Trustworthiness essentially means the degree of user confidence that the system
will operate as they expect and that the system will not ‘fail’ in normal use.

2.2.2 Availability:
The ability of the system to deliver services when requested. There is no error in the program
while executing the program.

2.2.3 Reliability:
The ability of the system to deliver services as specified. The program is compatible with all
types of operating system without any failure.

2.2.4 Safety:
The ability of the system to operate without catastrophic failure. This program is user friendly
and it will never effects the system.

2.2.5 Security:
The ability of the system to protect itself against accidental or deliberate intrusion.

2.3 Details of the software


Here, the coding of our project is done in Microsoft Visual C++ which is a commercial
integrated development environment (IDE) with OpenGL (Open Graphics Library) which is a standard
specification to produce 2D and 3D computer graphics. We use, the OpenGL Utility Toolkit called
GLUT which is a library of utilities for OpenGL programs.

2.3.1 Microsoft Visual C++


Microsoft Visual C++ is a commercial integrated development environment (IDE) product
engineered by Microsoft for the C, C++ and C++/CLI programming languages. It has tools for
developing and debugging C++ code, especially code written for the Microsoft Windows API,
OpenGL API, the DirectX API and the Microsoft .NET Framework.

Dept. of CSE, SCE Page 5


Graphical simulation of a Ship

2.3.2 OpenGL and GLUT


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, describing a set of
functions and the precise behaviors that they must perform. From this specification, hardware vendors
create implementations - libraries of functions created to match the functions stated in the OpenGL
specification, making use of hardware acceleration where possible. Hardware vendors have to meet
specific tests to be able to qualify their implementation as an OpenGL implementation.

GLUT is the OpenGL Utility Toolkit, a window system independent toolkit for writing
OpenGL programs. It implements a simple windowing application programming interface (API)for
OpenGL. GLUT makes it considerably easier to learn about and explore OpenGL programming.
GLUT provides a portable API so you can write a single OpenGL program that works across all PC
and workstation OS platforms.

2.4 Software requirements


❖ OPERATING SYSTEM : Windows 98, Windows XP, Windows Vista,
Windows 7
❖ FRONT END : Microsoft Visual Studio 2010
❖ CODING LANGUAGE : C++

2.5 Hardware requirements


❖ SYSTEM : Pentium IV 2.4 GHz or above
❖ HARD DISK : 40 GB, 80 GB, 160 GB or above
❖ MONITOR : 15 VGA colour
❖ RAM : 256 MB, 512 MB, 1 GB or above

Dept. of CSE, SCE Page 6


Graphical simulation of a Ship

CHAPTER 3
DESIGN

Data flow design is as shown below - covering the flow of the data in the system. It describes
the relation between user input and the system behavior.

Figure No. 3.1 Flow chart for Simulation of a Ship.

Dept. of CSE, SCE Page 7


Graphical simulation of a Ship

3.1 Execution Steps

1. Build the project.


2. Debug / Run the project.
3. The first screen is the cover screen containing the information about the project and contributors.
4. Press enter.
5. This changes the screen to the first output screen containing the ship on the ocean with a
backdrop of mountains.
6. The screen also includes a plane moving across the sky at regular intervals to produce a frame of
reference for the ship.
7. Press Y to output Early Morning screen.
8. Press M to output Morning screen.
9. Press A to output Afternoon screen.
10. Press E to output Evening screen.
11. Press N to output Night screen.
12. Press D to output Mid-Night screen.
13. To move forward press 6.
14. To move backward press 4.
15. To shoot a missile press Z.

Dept. of CSE, SCE Page 8


Graphical simulation of a Ship

CHAPTER 4
IMPLEMENTATION
To implement the Current system we have used different functions of our project which are as follows:

4.1 USER DEFINED FUNCTIONS

➢ frontscreen ()
Print the introduction screen showing project name and group members names
➢ Drawarc(float sa,float ea,float cx,float cy,float rd)
To draw sun and moon using arcs
➢ cloud(int m, int n)
To draw clouds.
➢ ship(float x)
To simulate ship object.
➢ water ()
To simulate water on the ocean
➢ mountain ()
To simulate mountains behind the ship
➢ flag ()
To display flag on the ship
➢ crackers ()
To simulate rocket ejected from the ship
➢ plane ()
To simulate plane in the sky which appears at regular intervals.
It has a certain speed to give a frame of reference for the ship

Dept. of CSE, SCE Page 9


Graphical simulation of a Ship

4.2 BUILT IN FUNCTIONS


• voidglClear (GLbitfieldmask);
- 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.
- It clears buffers to preset values.

• voidglClearColor (GLclampfred, GLclampfgreen, GLclampfblue, GLclampfalpha);


- red, green, blue, alpha – specify the red, green, blue and alpha values used when the color
buffers are cleared. The initial values are all 0.
- It specifies clear values for the color buffers.

• void glColor3f (GLfloatred, GLfloatgreen, GLfloatblue);


- red, green, blue – specify new red, green, and blue values for the current color.
- It sets the current color.

• glutCreateWindow (char *name);


- name – ASCII character string for use as window name.
- It creates a top-level window.

• voidglutDisplayFunc (void (*func) (void));


- func – the new display callback function.
- It sets the display callback for the current window.

• voidglutInitWindowSize (intwidth, intheight);


- width– width in pixels.
- height – height in pixels.
- It is used to set the initial window size.

• voidglutMainLoop (void);
- It enters the GLUT event processing group. 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.

Dept. of CSE, SCE Page 10


Graphical simulation of a Ship

• voidglutPostRedisplay (void);
- It marks the current window as needing to be redisplayed.

• void display (void);


- It contains the function definition for display callback.

• voidglutIdleFunc (void (*func) (void));


- It sets the global idle callback.

Dept. of CSE, SCE Page 11


Graphical simulation of a Ship

CHAPTER 5
TESTING

Testing has been conducted as tabulated below.

Functions with parameters


No Expected result Actual result Comments
under test

The project details with The project


The initial output screen with
1 college name must be details is PASS
project details
visible visible.

The Ship must be


The ship is
2 Screen 1 visible in the initial PASS
visible
output

When ‘6’ is pressed,


the ship should move
The keys work
forward.
4 Move function as they are PASS
When ‘4’ is pressed,
supposed to.
the ship moves
backwards.

y -> “Early morning”


m-> “Morning”
The keys work
a-> “Afternoon”
5 Changing Screens as they are PASS
e-> “Evening”
expected
n-> “Night”
d-> “Midnight”

When ‘z’ is pressed, a When ‘z’ is


projectile in the form of pressed, the
6 Shooting Rocket PASS
a rocket is ejected from projectile is
the ship. ejected

Dept. of CSE, SCE Page 12


Graphical simulation of a Ship

CHAPTER 6
SNAPSHOTS

6.1 Main Page

Figure 6.1: Main Page


6.2 Initial output screen

Figure 6.2: Initial Output Screen

Dept. of CSE, SCE Page 13


Graphical simulation of a Ship

6.3 Early Morning Screen

Figure 6.3: Early Morning Screen

6.4 Morning Screen

Figure 6.4: Morning Screen

Dept. of CSE, SCE Page 14


Graphical simulation of a Ship

6.5 Afternoon Screen

Figure 6.5: Afternoon Screen

6.6 Evening Screen

Figure 6.6: Evening Screen

Dept. of CSE, SCE Page 15


Graphical simulation of a Ship

6.7 Night Screen

Figure 6.7: Night Screen

6.8 Midnight Screen

Figure 6.8: Midnight Screen

Dept. of CSE, SCE Page 16


Graphical simulation of a Ship

CHAPTER 7
CONCLUSION

The development of the project is not an easy process as it involves lot of challenges in different
stages of software analysis, design, coding and testing.

Having understood the requirements properly and implementing the solutions as per the
expectation as brought to the closure of the project. We have tried our best to make this project very
realistic, so that the user does not face any trouble when switching over from any real life graphics
project to this highly useful one.

We consider this an entry into the world of visualization and simulation and look forward to work
on more interesting projects in future. Throughout the duration of this project we learnt new OpenGL
functions which we were not familiar with prior to us starting this endeavor. We learnt how to create
our own functions to make objects work the way we want to

Finally we would like to say that while working on this project we learnt collaborating to get things
done on time, and creating a fully working project within a deadline made us improve our time
management skills. We look forward to making more projects like these in future.

Dept. of CSE, SCE Page 17


Graphical simulation of a Ship

BIBILOGRAPHY

Reference Books
[1] “Interactive Computer Graphics- A Top-Down Approach Using OpenGL” By
Edward Angel
[2] “Computer Graphics under C” By Yeshwant Kanetkar
[3] The openGL programming guide – The red book
[4] OpenGL 4.6 Reference Guide Khronos Group(You?) | 2018
[5] Learn OpenGL Learn modern OpenGL graphics programming in a step-by-step fashion.
Joey de Vries(You?)|2020

Websites
❖ www.opengl.org
❖ www.google.co.in(OpenGLprojects)
❖ www.wikipedia.com
❖ https://www.khronos.org/opengles/resources
❖ https://people.ece.ubc.ca/leei/478/resources.html
❖ https://riggaroo.dev/resources-for-learning-opengl-an-android-developers-guide/
❖ http://www.opengl-tutorial.org/miscellaneous/useful-tools-links/

Dept. of CSE, SCE Page 18

You might also like