Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 12

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

“JnanaSangama”, Belgaum-590018

A Mini Project Report On


SHIP SINKING USING OPENGL GLUT
SUBMITTED IN PARTIAL FULFILMENT FOR 6TH SEMESTER
BACHELOR OF ENGINEERING
IN

COMPUTER SCIENCE AND ENGINEERING


SUBMITTED BY
PAVAN M [1JB21CS103]

UNDER THE GUIDANCE OF

Mrs. Anusha M
Assistant Professor
Dept. of CSE, SJBIT

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SJB INSTITUTE OF TECHNOLOGY
#67, BGS HEALTH & EDUCATION CITY, DR.VISHNUVARDHAN ROAD, KENGERI,
BENGALURU-560060, KARNATAKA, INDIA.
2021 - 2022

Sl.No. Assignment No. Total Marks Marks


Obtained

1 Assignment 1 10
2 Assignment 2 10
Total Marks:

Student Signature: Faculty Signature:


CHAPTER 1

INTRODUCTION TO OPENGL

1.1 WHAT IS OPENGL ?

OpenGL (Open Graphics Library) is an industry-standard API for rendering 2D and


3D vector graphics. Developed by Silicon Graphics Inc. (SGI) in the early 1990s,
OpenGL has become a widely adopted tool for creating graphics in applications
ranging from video games and simulations to scientific visualizations and CAD
software. Its cross-platform nature and broad support across different hardware and
operating systems have made it a cornerstone in the graphics development world.

Core Concepts
OpenGL Context
An OpenGL context is a key concept, encapsulating all the states required for rendering.
This includes configurations for shaders, textures, buffers, and more. The context is typically
created and managed through a windowing system or a library such as GLFW or SDL,
which abstracts platform-specific details. Creating an OpenGL context involves initializing
the library, creating a window, and making the context current in the rendering thread.

Shaders
Shaders are small programs that run on the GPU, allowing for highly customizable
graphics processing. OpenGL primarily uses two types of shaders:

● Vertex Shader: Processes each vertex’s attributes (like position, normal,


texture coordinates) and performs transformations to convert 3D
coordinates to 2D screen coordinates.
● Fragment Shader: Processes fragments (potential pixels) generated by rasterizing the
vertices. It determines the color and other attributes of each pixel.
Other types of shaders include geometry shaders, tessellation control and evaluation
shaders, and compute shaders, which offer more advanced control over graphics
and computation processes.
Ship Sinking using OpenGL

Buffers
Buffers are used to store data such as vertex positions, indices, and other attributes
necessary for rendering:
● Vertex Buffer Object (VBO): Stores vertex data.
● Element Buffer Object (EBO): Stores indices for indexed drawing, allowing for
efficient reuse of vertex data.
● Frame Buffer Object (FBO): Used for off-screen rendering, enabling advanced
techniques like shadow mapping and post-processing.

Vertex Array Object (VAO)


The VAO stores the configuration of vertex attribute pointers and their associated
VBOs. This encapsulates the state needed to specify vertex data, making it easier to
switch between different sets of vertex data.

Transformation Matrices
Transformations are fundamental to graphics programming, allowing objects to be
moved, rotated, and scaled within the scene. OpenGL uses transformation matrices
for these operations:
● Model Matrix: Transforms object coordinates to world coordinates.
● View Matrix: Transforms world coordinates to camera (view) coordinates.
● Projection Matrix: Transforms camera coordinates to screen coordinates,
applying perspective or orthographic projection.

Basic Workflow in OpenGL


Understanding the basic workflow in OpenGL is crucial for developing graphics applications.
This workflow includes setting up the environment, creating shaders, managing buffers, and
executing the rendering loop. Here’s an in-depth look at each step:
1. Initialization
Creating an OpenGL Context
An OpenGL context represents all OpenGL state required to perform
rendering. This context must be created before issuing any OpenGL
commands. The creation of the OpenGL context is typically handled by a
windowing library such as GLFW, SDL, or GLUT.

Dept. Of CSE 2023 - 24 Page 2


Ship Sinking using OpenGL

2. Setup Shaders
Shaders are small programs that run on the GPU. They are written in GLSL
(OpenGL Shading Language) and compiled at runtime. The main types of
shaders are vertex and fragment shaders.
3.Load Buffers
Buffers store vertex data and other attributes necessary for rendering. The most
commonly used buffers are the Vertex Buffer Object (VBO), Element Buffer Object
(EBO), and Vertex Array Object (VAO).
4.Rendering Loop
The rendering loop, also known as the main loop, is where the drawing happens.
This loop clears the screen, uses the shader program, binds the VAO, and issues
the draw call. It typically runs until the window is closed.
5.Cleanup
After the rendering loop exits, it's important to clean up the resources to prevent
memory leaks.

1.2 COMMON PRIMITIVES

1. GL_POINTS : Renders individual points.


2. GL_LINES : Renders lines connecting pairs of vertices.
3. GL_LINE_STRIP : Renders a series of connected lines.
4. GL_LINE_LOOP : Renders a series of connected lines, closing the loop.
5. GL_TRIANGLES : Renders individual triangles.
6. GL_TRIANGLE_STRIP : Renders a strip of connected triangles.
7. GL_QUADS : Renders individual quadrilaterals. (Deprecated in modern OpenGL)
8. GL_QUAD_STRIP : Renders a strip of connected quadrilaterals. (Deprecated)

Dept. Of CSE 2023 - 24 Page 3


CHAPTER 2

INTRODUCTION ABOUT PROJECT

Simulating a ship sinking using OpenGL is an engaging and complex project that
involves various aspects of computer graphics, physics simulation, and possibly
even some aspects of fluid dynamics. This project can be broken down into several
core components: modeling the ship, animating its sinking process, applying realistic
physics, and rendering the scene with appropriate visual effects. This simulation can
be used for educational purposes, video games, or even scientific visualizations.

2.1 PROJECT COMPONENTS

1.Ship Modeling
The first step in simulating a ship sinking is creating a 3D model of the ship. This
model can be created using 3D modeling software such as Blender or Maya and
then exported to a format that can be loaded into OpenGL, like OBJ or STL.
● Vertices and Normals: The model consists of vertices that define the shape
of the ship and normals that are used for lighting calculations.
● Textures: Applying textures to the model adds realism by simulating the
appearance of materials like metal and wood.
2.Physics Simulation
Simulating the sinking of a ship involves applying the laws of physics to create
realistic movement and interaction with water. This includes:
● Buoyancy: Calculating the buoyant force acting on the ship based on the volume
of water displaced.
● Gravity: Applying gravitational force to make the ship sink.
● Water Resistance: Simulating drag force that opposes the movement of the
ship through water.
● Collision Detection: Ensuring that the ship interacts correctly with the water
surface and ocean floor.
Ship Sinking using OpenGL

3.Animation
Animating the ship’s sinking process requires updating the position, rotation, and
possibly the deformation of the ship model over time. Keyframe animation or
procedural animation techniques can be used.
● Keyframe Animation: Predefined keyframes specify the ship’s position and
orientation at certain times, with interpolation between these keyframes.
● Procedural Animation: The ship’s movement is calculated in real-time based on
physics simulations.
4.Rendering
Rendering the scene involves setting up the camera, lighting, and materials to create
a visually appealing simulation. This includes:
● Lighting: Using directional, point, or ambient light sources to illuminate the scene.
● Shading: Applying shaders to achieve realistic water and ship materials.
● Special Effects: Adding effects like splashes, bubbles, and debris to enhance realism.

Implementing the Simulation


1. Setting Up OpenGL
Before rendering anything, an OpenGL context must be created. This involves
initializing the windowing system and setting up necessary OpenGL states.

2. Loading the Ship Model


The ship model is loaded from a file and stored in buffers for rendering.
3. Physics Simulation
Implementing the physics simulation involves calculating forces and updating
the ship’s position and orientation.
4. Rendering the Scene
Rendering the scene involves setting up the camera, lighting, and drawing
the ship model.

Dept. Of CSE 2023 - 24 Page 5


Ship Sinking using OpenGL

CHAPTER 3

HARDWARE AND SOFTWARE REQUIREMENTS

Creating and running the ShipSinking OpenGL project requires a combination of both
hardware and software components. These components ensure that the development
environment is robust, the performance is adequate, and the user experience is seamless.

3.1 HARDWARE REQUIREMENTS

Processor (CPU)

• Intel Core i5 or AMD Ryzen 5 (or equivalent) for general development and gameplay.
• Higher-end CPUs (Intel Core i7/i9 or AMD Ryzen 7/9) can be beneficial for more
complex projects or higher performance.

Graphics Card (GPU)

• NVIDIA GeForce GTX 1050 or AMD Radeon RX 560 (or equivalent) for basic
OpenGL development.
• More powerful GPUs like the NVIDIA GeForce RTX series or AMD Radeon RX
6000 series are beneficial for higher performance and future-proofing.

Memory (RAM)

• 8GB RAM for basic development and testing.


• 16GB or more is recommended for a smoother experience, especially when
multitasking with other applications.

Dept. Of CSE 2023 - 24 Page 6


Ship Sinking using OpenGL

Storage

• Solid State Drive (SSD) with at least 256GB of storage for fast read/write speeds and
quick access to development tools and game assets.
• Larger capacity (512GB or more) SSDs or additional HDDs are recommended for
storing larger projects and additional data.

3.2 SOFTWARE REQUIREMENTS

Operating System :

• Windows 10/11, macOS, or a modern Linux distribution (e.g., Ubuntu, Fedora).

OpenGL Libraries :

• OpenGL (core library)


• GLU (OpenGL Utility Library)
• GLUT or FreeGLUT (OpenGL Utility Toolkit for window management and input
handling)

Development Environment :

• Microsoft Visual Studio (Windows)


• Code::Blocks (cross-platform)

Compiler :

• GCC (GNU Compiler Collection, available on Linux and macOS)


• MSVC (Microsoft Visual C++, available with Visual Studio on Windows)

Dept. Of CSE 2023 - 24 Page 7


CHAPTER 4

SYSTEM DESIGN

4.1 INTRODUCTION

Creating a system to simulate a ship sinking using OpenGL involves designing both the
software architecture and the workflow to handle various tasks such as physics
simulation, rendering, and user interaction. This system design will outline the primary
components and their interactions, ensuring a modular and efficient implementation.

4.2 SYSTEM ARCHITECTURE

The system can be divided into several main components:


1. Initialization and Setup: Setting up the OpenGL context, window, and necessary libraries.

2. Resource Management: Loading and managing models, textures, and shaders.


3. Physics Engine: Handling the physics calculations for the ship's
movement and interactions with water.
4. Rendering Engine: Rendering the scene, including the ship, water, and environment.
5. User Input Handling: Managing user inputs to control the simulation.
6. Main Loop: The core loop that drives the simulation by updating physics and
rendering frames.

Component Breakdown

1. Initialization and Setup


This component handles the creation of the OpenGL context and window, as
well as the initialization of GLEW and setting up the rendering environment.
2. Resource Management
This component handles loading and managing resources such as 3D models,
textures, and shaders. It typically includes functions to load models from files,
compile shaders, and bind textures.
3. Physics Engine
The physics engine is responsible for simulating the physical behavior of the ship and

its interaction with the water. This includes buoyancy, gravity, and collision detection.
Ship Sinking using OpenGL

4.Rendering Engine
The rendering engine is responsible for drawing the scene, including the ship,
water, and any other environmental elements. It handles setting up the camera,
lighting, and drawing objects.
5.User Input Handling
This component handles user inputs such as keyboard and mouse events to
control the simulation, such as pausing, resetting, or adjusting the camera view.
6.Main Loop
The main loop drives the simulation by continuously updating the physics and rendering

the scene. It also handles user inputs and ensures the window is responsive.

Detailed Component Interaction

1. Initialization and Setup:


● Initializes GLFW and GLEW.
● Creates a window and OpenGL context.
● Sets up OpenGL states like depth testing.
2. Resource Management:
● Loads the ship model, textures, and shaders.
● Stores resources in a resource manager for easy access.
3. Physics Engine:
● Updates the ship's position and velocity based on forces like gravity and buoyancy.
● Checks for collisions with the water surface.
4. Rendering Engine:
● Sets up the camera and projection matrix.
● Draws the ship and water using the loaded shaders and textures.
5. User Input Handling:
● Processes keyboard and mouse inputs to control the simulation and camera.
6. Main Loop:
● Continuously updates physics and renders the scene.
● Handles user inputs and maintains window responsiveness.

Dept. Of CSE 2023 - 24 Page 9


Ship Sinking using OpenGL

Detailed Dataflow

1. Initialization and Setup


Input: Window dimensions, OpenGL context settings.
Output: OpenGL context, window handle, initial OpenGL
state. Steps:
1.Initialize GLFW and create a window.
2.Set up OpenGL context and initialize GLEW.
3.Configure initial OpenGL states (e.g., depth testing).
2. Resource Management
Input: File paths for models, textures, shaders.
Output: Loaded resources (models, textures, shader
programs). Steps:
1.Load 3D models from files.
2.Load and bind textures.
3.Compile and link shader programs.
3. Physics Simulation
Input: Current state of the ship (position, velocity), environmental parameters
(gravity, water density).
Output: Updated state of the
ship. Steps:
1.Calculate forces acting on the ship (gravity, buoyancy).
2.Update the ship's velocity and position based on these forces.
3. Check for collisions with the water surface and adjust the ship's state accordingly.
4. Rendering
Input: Camera parameters, light settings, current state of the ship and water.
Output: Rendered frame displayed on the
screen. Steps:
1.Set up the camera and projection matrices.
2.Bind shader programs and set uniforms.
3.Draw the ship and water using the current state data.

Dept. Of CSE 2023 - 24 Page 10


Ship Sinking using OpenGL

5.User Input Handling


Input: User actions (keyboard and mouse events).
Output: Updated camera parameters, simulation control commands.
Steps:
1. Capture user inputs from the window system.
2. Update camera position and orientation based on inputs.
3. Handle simulation control inputs (e.g., pause, reset).
6.Main Loop
Input: Initialization data, current state of the ship and environment, user inputs.
Output: Continuously updated and rendered
simulation. Steps:
1.Calculate the time elapsed since the last frame (delta
time).
2.Process user inputs.
3.Update the physics simulation.
4.Render the current state of the simulation.
5.Poll for events and swap buffers.

Dept. Of CSE 2023 - 24 Page 11

You might also like