Final CG

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 43

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

JnanaSangama, Belgaum-590018

A COMPUTER GRAPHICS LABORATORY WITH MINI-PROJECT REPORT (18CSL67)


ON

“CATCH ME GAME”
Submitted in Partial fulfillment of the Requirements for VI of the Degree of

Bachelor of Engineering in Computer Science & Engineering


By

T BHARATH KUMAR REDDY(1CR20CS201)

SHREYA N S (1CR20CS201)

Under the Guidance of,


Dr. V N Manju, Assistant Professor, Dept. of CSE

Mr. Shivraj V B., Assistant Professor, Dept. of CSE

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CMR INSTITUTE OF TECHNOLOGY

#132, AECS LAYOUT, IT PARK ROAD, KUNDALAHALLI, BANGALORE-560037


CMR INSTITUTE OF TECHNOLOGY
#132, AECS LAYOUT, IT PARK ROAD, KUNDALAHALLI,BANGALORE-560037

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CERTIFICATE
Certified that the Computer Graphics Mini-project work entitled “CATCH ME GAME” carried out
by Mr T BHARATH KUMAR REDDY, USN 1CR20CS201, Ms. SHREYA NS, USN
1CR20CS181, bonafide students of CMR Institute of Technology, in partial fulfillment for the VI
semester requirements toward the degree of Bachelor of Engineering in Computer Science and
Engineering of the Visveswaraiah Technological University, Belgaum during the year 2022-2023. It
is certified that all corrections/suggestions indicated for Internal Assessment have been incorporated in
the Report deposited in the departmental library. The mini-project report has been approved as it
satisfies the academic requirements in respect of Mini-Project work prescribed for the course,
Computer Graphics and Visualization Laboratory with Mini-project.

Dr. V N Manju Dr. Shreekanth M Prabhu


Assistant Professor Professor & Head
Dept. of CSE, Dept. of CSE, CMRIT
CMRIT

External Viva

Name of the Examiners Signature with Date

1.

2.

ii
DECLARATION

We, the students of Computer Science and Engineering, CMR Institute of Technology,
Bangalore declare that the mini-project work entitled "CATCH ME GAME" has been
successfully completed under the guidance of Prof. V N Manju, Assistant Professor and Mr.
Shivraj V B, Assistant Professor Computer Science and Engineering Department, CMR Institute
of technology, Bangalore. This work is submitted in partial fulfillment of the requirements
toward the VI semester Computer Graphics Laboratory with Mini-Project (18CSL67) for the
degree of Bachelor of Engineering in Computer Science and Engineering during the academic
year 2022 - 2023. Further the matter embodied in the project report has not been submitted
previously by anybody toward the requirements of Computer Graphics Laboratory with Mini-
Project (18CSL67) in the VI degree or diploma to any university.

Place: CMR Institute of Technology,

Bengaluru Date:

Team members: Signature

T BHARATH KUMAR REDDY (1CR20CS201)

SHREYA NS (1CR20CS181)

iii
ABSTRACT

The "Catch Me" project develops an immersive game using OpenGL in C. Players aim to catch
moving objects within a time limit. Leveraging OpenGL, the project delivers smooth animations,
responsive controls, and an immersive environment. It showcases the potential of OpenGL for
creating visually captivating gaming experiences. The objective is to engage players through
intuitive gameplay and visually appealing graphics. "Catch Me" highlights OpenGL's power in
creating dynamic and interactive gaming environments, offering an enjoyable and challenging
game.

iv
ACKNOWLEDGEMENT

I take this opportunity to express my sincere gratitude and respect to CMR Institute of
Technology, Bengaluru for providing me a platform to pursue my studies and carry out my final
year project
I have a great pleasure in expressing my deep sense of gratitude to Dr. Sanjay Jain,
Principal, CMRIT, Bangalore, for his constant encouragement.
I would like to thank Dr. Shreekanth M Prabhu, Professor and Head, Department of
Computer Science and Engineering, CMRIT, Bangalore, who has been a constant support and
encouragement throughout the course of this project.
I consider it a privilege and honor to express my sincere gratitude to my guide
Prof. V N Manju, Assistant Professor and Mr. Shivraj V B, Assistant Professor Computer
Science and Engineering Department, for the valuable guidance throughout the tenure of this
review.
I also extend my thanks to all the faculty of Computer Science and Engineering who
directly or indirectly encouraged me.
Finally, I would like to thank my parents and friends for all their moral support they have
given me during the completion of this work.

v
TABLE OF

Page No.
Certificate ii
Declaration iii
Abstract iv
Acknowledgement v
Table of contents vi
List of Figures viii
List of Tables ix
List of Abbreviations x
1 INTRODUCTION 1
1.1 Problem Statement 1
1.2 Objective 1
1.3 Functionalities 2
1.4 OpenGL Package 2
1.5 VS CODE and WSL 3
2 DESIGN 4
2.1 Conceptual Design 4
2.2 Flowchart 5
2.3 Storyboard 5
3 IMPLEMENTATION 10
3. 1 Initialization 10
3.2 Modeling 11
3.3 Viewing 20
3.4 Interactions 21
Keyboard, Mouse
3.5 Animation 22
4 RESULTS AND DISCUSSION 24
4.1 Front Page 24

vi
4.2 Welcome Page 25
4.3 How to play Page 26
4.4 Levels Page 27
4.5 Game Page 28
4.6 Game Over Page 29
5 CONCLUSION 30
REFERENCES 31
APPENDIX A Installation Instructions 32
APPENDIX B OpenGL Functions 34

vii
LIST OF FIGURES

Page No.
Fig 2.1 Game Design 4
Fig 2.2 Flow Chart 5
Fig 2.3 Frame 1 6
Fig 2.4 Frame 2 7
Fig 2.5 Frame 3 7
Fig 2.6 Frame 4 8
Fig 2.7 Frame 5 8
Fig 2.8 Frame 6 9
Fig 4.1 Front page 24
Fig 4.2 Start menu 25
Fig 4.3 How to play screen 26
Fig 4.4 Screen to select level 27
Fig 4.5 Game Screen 28
Fig 4.6 Game Over Screen 29

viii
LIST OF ABBREVIATIONS

GL Graphics Library
GLUT Graphics Library Utility Toolkit
RGB Red Green Blue
2D Two-dimensional
GLU Graphics Library Utility

ix
Catch Me

CHAPTER 1

INTRODUCTION
This project is an interactive game developed using the OpenGL library in C. It utilizes the
GLUT (OpenGL Utility Toolkit) to create a user-friendly interface where players can engage
in gameplay through mouse and keyboard inputs. The game features immersive visuals and
offers various challenges for players to overcome, aiming for high scores. The
implementation demonstrates the power of OpenGL in real-time rendering, showcasing its
potential for creating engaging and visually appealing games. This report provides an
overview of the game's features and discusses possibilities for future enhancements and
broader applications in the gaming industry.

1.1 Problem Statement

This project focuses on developing an interactive game called "Catch Me" using the OpenGL
library in C. The goal of this project is to create an intuitive and immersive game where
players must catch moving objects within a specified time limit. By harnessing the
capabilities of OpenGL, the project aims to deliver smooth animations, responsive controls,
and an immersive gaming environment. The objective is to provide players with a
challenging and enjoyable game that highlights the potential of OpenGL in creating
interactive and visually captivating gaming experiences.

1.2 Objective

The objective of this project was to utilize the OpenGL library and its functions to build a
game application called "Catch Me." The main focus was on understanding and
implementing various OpenGL functions and techniques to create interactive graphics and
user interfaces. The project aimed to explore the capabilities of OpenGL in real-time
rendering, window management, and handling user input. The objective was not solely to
develop the game itself, but rather to utilize OpenGL as a powerful tool for building dynamic
and visually appealing applications.
Catch Me

1.3 Functionalities

 Start Game: This functionality allows the player to initiate the game. It may be
implemented as a button or a menu option that the player can click or select to begin
playing.
 Catching Object: The main objective of the game is to catch a moving object on the
screen. The object could be represented as an image or a sprite that the player needs to
click on or interact with using the game controls. The player's ability to accurately catch
the object determines their performance in the game.
 Score Tracking: The game keeps track of the player's score as they successfully catch the
moving object. Each time the player catches the object, their score increases. The score is
usually displayed on the screen during gameplay, allowing the player to monitor their
progress and compare it with previous attempts.
 Chances: The player is typically given a limited number of chances or attempts to catch
the object successfully. If the player fails to catch the object within the given number of
chances, the game may end or display a "Game Over" message. The concept of chances
adds an element of challenge and encourages players to focus and improve their
performance.
 Game Over: When the player exhausts all their chances, the game enters the "Game
Over" state. This state indicates that the player has completed their gameplay session, and
no further interaction is possible. It may display a message to inform the player that the
game is over and provide options to restart the game or return to the main menu.

1.4 OpenGL Package

The OpenGL package plays a pivotal role in the development of our game, providing
essential features that contribute to its success. OpenGL is a powerful and widely-used
graphics library that enables us to create visually stunning and immersive experiences. Its
importance lies in its ability to harness the hardware acceleration of modern GPUs,
optimizing rendering performance and enhancing the overall graphical quality of our game.
With OpenGL, we can utilize advanced rendering techniques such as shading, lighting, and
texture mapping to bring our game world to life. It offers a rich set of features, including
Catch Me

support for 2D and 3D graphics, vertex and fragment shaders, transformation matrices, and
rendering pipelines. These features empower us to create realistic environments, realistic
character animations, and visually appealing special effects. OpenGL provides cross-
platform compatibility, allowing our game to run seamlessly on different operating systems
and devices. Overall, the OpenGL package has been instrumental in enabling us to deliver a
visually captivating and engaging gaming experience to our players.

1.5 VS CODE and WSL


The "Catch Me" game was developed using a powerful trio of tools: Visual Studio Code (VS
Code), Windows Subsystem for Linux (WSL), and a reliable C compiler. This winning
combination allowed for seamless project development and execution. In this page, we'll
delve into how these tools helped us to create an engaging and interactive game experience.

Visual Studio Code (VS Code) is a widely acclaimed source code editor developed by
Microsoft. It provides a user-friendly interface and a vast extension library, making it a
popular choice among programmers. With its rich features and flexibility, VS Code offers a
customizable workspace that enhances productivity and streamlines the development process.

Windows Subsystem for Linux (WSL) is a compatibility layer provided by Microsoft. It


allows developers to run a Linux environment directly on Windows. By integrating the best
of both worlds, WSL enables developers to work with Linux tools and utilities while taking
advantage of the Windows ecosystem. With WSL, developers can seamlessly develop and
test projects without the need for dual-booting or virtual machines.

A reliable C compiler is an essential component for running C projects. It translates the


human-readable C code into machine-executable instructions. The C compiler takes care of
tasks such as syntax checking, optimizing code, and generating executable files. With a solid
C compiler, developers can ensure their code runs efficiently and accurately.

When combined, these three tools provide a powerful and efficient development
environment. Developers can leverage the user-friendly interface and extensive extension
library of VS Code while utilizing the Linux capabilities and utilities offered by WSL. The C
compiler completes the trio by enabling the execution of C code seamlessly.
Catch Me

CHAPTER 2

DESIGN
The design chapter of this project provides an overview of the Catch Me game's visual and
structural components. It includes a flowchart illustrating the game's logical flow, a
conceptual design showcasing the layout and structure, and a storyboard depicting the step-
by-step functionality of the game. These design elements help us understand how the game
works and what it looks like, making it engaging and enjoyable for players.

2.1 Conceptual Design

Fig 2.1 Game Design

The game screen design for the "Catch Me" game features a simple and intuitive layout. The
objective of the game is to click on the moving object to score points. The design emphasizes
a user-friendly interface, making it easy for players to interact with the game and aim for a
high score. The visual elements are engaging and captivating, ensuring an enjoyable gaming
experience for players of all skill levels.
Catch Me

2.2 Flowchart
The game begins with a main menu, offering options to start, access controls, select levels, or
read about the game. Choosing to start takes the player to the gameplay screen, where they
must catch moving objects by clicking. Successful catches increase the score, while misses
reduce chances. If the player runs out of chances, the game over screen appears. The main
menu also provides options to access controls and learn about the game. Exiting the game is
possible through a dedicated option.

Fig 2.2 Flow Chart

2.3 Storyboard
Frame 1:

 The user launches the application and sees the home screen with project details.
 A prompt on the screen instructs the user to Press “Enter” to Start
Catch Me

Fig 2.3 Frame 1

Frame 2:

 The user presses “Enter” and is taken to the screen where different options are
present.
 The user can press the respective number to perform the respective action.
Catch Me

Fig 2.4 Frame 2


Frame 3:

 The user presses “2” and a screen where the instructions on how to play the game is
showed

Fig 2.5 Frame 3


Catch Me

Frame 4:

 The user left clicks and is taken to the main screen where they select the level.

Fig 2.6 Frame 4


Frame 5:

 The user left clicks and is taken to the main screen where they start the game.

Fig 2.7 Frame 5


Catch Me

Frame 6:

 The user finishes playing the game and is taken to the game over page.

Fig 2.8 Frame 6


Catch Me

CHAPTER 3

IMPLEMENTATION
The "Catch Me" game was implemented using a C compiler and the GLUT library, with
dependencies such as OpenGL, GLU, and GLUT installed. The code was carefully structured
to handle user input and provide essential game functionalities. Game mechanics, object
movement, were implemented to create an engaging gameplay experience. OpenGL's
graphical rendering capabilities were utilized for visuals, while user interaction was
incorporated for changing screens using keyboard inputs.

3.1 Initialization
main()

This function sets up a window using GLUT for a game called "CATCH ME GAME". It
defines the window size and position, creates the window with the specified title, and
initializes the necessary parameters. Callback functions are registered to handle display,
keyboard, mouse, and window resizing events. The main loop is started, which continuously
checks for events and updates the game. Overall, this code establishes the foundation for the
interactive game window and event handling.

int main(int argc, char **argv)

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(1280, 1024);

glutInitWindowPosition(0.0, 0.0);

glutCreateWindow("CATCH ME IF U CAN!!!");

initfun();

glutDisplayFunc(display);

glutKeyboardFunc(keyboard);
Catch Me

glutMouseFunc(mouse);

glutReshapeFunc(reshape);

glutMainLoop();

return 0;

myinit()

This function initializes the OpenGL rendering settings by setting the projection mode to
GL_PROJECTION and loading the identity matrix. It then sets up a 2D orthographic
projection using gluOrtho2D, defining the viewing volume as a rectangle with coordinates (0,
0) as the bottom-left corner and (1280, 1024) as the top-right corner. Finally, it calls the
function mypos() to initialize the position of the objects in the scene.

void initfun()

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(0, 1280, 0, 1024);

mypos();

3.2 Modelling
Display()

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
if (cmrFlag == 0)
{
cmr();
}
Catch Me

if (startFlag == 0 && cmrFlag == 1)


{
glColor3f(1, 1, 1);
glRectf(0, 0, 800, 600);
glColor3f(0, 0, 0);
glRectf(10, 10, 1270, 1014);
glColor3f(0.6, 0.7, 0.8);
glRasterPos2f(300, 900);
for (w = 0; w < sizeof(wel); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, wel[w]);
glRasterPos2f(250, 850);
for (w = 0; w < sizeof(max); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, max[w]);
glColor3f(0.5, 0.1, 0.7);
glRasterPos2f(200, 700);
for (w = 0; w < sizeof(start); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, start[w]);
glColor3f(0.7, 0.8, 0.9);
glRasterPos2f(200, 600);
for (w = 0; w < sizeof(controls); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, controls[w]);
glColor3f(0.2, 0.5, 0.7);
glRasterPos2f(200, 500);
for (w = 0; w < sizeof(levels); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, levels[w]);
glColor3f(1.0, 0.8, 0.3);
glRasterPos2f(200, 400);
for (w = 0; w < sizeof(about); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, about[w]);
glFlush();
}
if (controlsFlag == 1) // to go controls window
{
controls1();
}
if (aboutFlag == 1) // to go about game window
{
aboutf();
}
if (levFlag == 1)
Catch Me

{
lev();
}
if (startFlag == 1) // to start game
{
glColor3f(100.0 / 256.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 1280, 0, 1024);
glColor3f(0.5,0.7,0);
glRectf(0, 0, 1280, 1024);
glColor3f(0, 100.0 / 256.0, 0); // b2
glRectf(70, 70, 860, 680);
glColor3f(0, 0, 0); // b3
glRectf(90, 90, 840, 660);
vs2 = score % 10;
vs1 = score / 10;
glRasterPos2f(100, 800);
for (i = 0; i < sizeof(sco); i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, sco[i]);
glRasterPos2f(170, 800);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, vs1 + 48);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, vs2 + 48);
if (hitFlag == 0)
{
glColor3f(1.0, 1.0, 1.0); // object;
drawStar((o.x1 + o.x2)/2.0f, (o.y1 + o.y2) / 2.0f, 20.0, 10);
glFlush();
if (o.x2 <= 840)
moveRight();
if (o.x2 > 840)
randomGenerate();
glFlush();
}
glColor3f(0, 0, 1);
glPointSize(5);
glBegin(GL_POINTS);
glVertex2f(x, y);
glEnd();
if (hitFlag == 1)
Catch Me

{
hitFlag = 0;
glColor4f(1.0, 1.0, 1.0, 1.0);
char b[20] = {"hit..."}, c[20] = {"lost.."};
glRasterPos2f(o.x1, o.y1);
if (messageTrue == 1)
{
score += 10;
for (int i = 0; i < 7; i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, b[i]);
glFlush();
}
for (int t = 0; t < 1000; t++)
for (int h = 0; h < 1000; h++)
for (int y = 0; y < 100; y++)
{
}
randomGenerate();
}
}
glFlush();
}

The display function is responsible for rendering the game's graphics on the screen. It begins
by clearing the color buffer, ensuring a clean canvas for drawing. The function then checks
various flags to determine the current state of the game. If the cmrFlag is not set, the cmr
function is called to display the camera view. If the startFlag is set, the game screen is
rendered with different colored rectangles, score display, and the moving star object. The
star's position is updated by calling the moveRight and randomGenerate functions based on
its current coordinates. If the hitFlag is set, the appropriate message is displayed, the score is
updated, and a new star is randomly generated. The function also handles displaying the
controls and about windows based on the corresponding flags. Overall, the display function
ensures the proper rendering of game elements based on the game's state and user interaction.

Primitives:
glClear(GL_COLOR_BUFFER_BIT): Clears the color buffer to prepare for drawing the next
frame.
Catch Me

glRectf(x1, y1, x2, y2): Draws a filled rectangle with the specified coordinates.
Algorithms:
gluOrtho2D(0, 1280, 0, 1024): Sets up a 2D orthographic projection matrix to define the
viewing volume.
glRasterPos2f(x, y): Sets the current raster position for subsequent bitmap character
rendering.
glutBitmapCharacter(font, character): Renders a bitmap character from the specified font at
the current raster position.
Startmenu()

void startmenu()
{
if (dirFlag == 1)
{
dirFlag = 0;
upFlag = 0;
yy1 -= 100;
yy2 -= 100;
glColor3f(0.6, 0.7, 0.8);
glRasterPos2f(300, 900);
for (w = 0; w < sizeof(wel); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, wel[w]);
glRasterPos2f(250, 850);
for (w = 0; w < sizeof(max); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, max[w]);
glColor3f(0.5, 0.1, 0.7);
glRasterPos2f(200, 700);
for (w = 0; w < sizeof(start); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, start[w]);
glColor3f(0.7, 0.8, 0.9);
glRasterPos2f(200, 600);
for (w = 0; w < sizeof(controls); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, controls[w]);
glColor3f(0.2, 0.5, 0.7);
glRasterPos2f(200, 500);
for (w = 0; w < sizeof(levels); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, levels[w]);
glColor3f(1.0, 0.8, 0.3);
glRasterPos2f(200, 400);
Catch Me

for (w = 0; w < sizeof(about); w++)


glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, about[w]);
glFlush();
}
if (upFlag == 1)
{
upFlag = 0;
dirFlag = 0;
yy1 += 100;
yy2 += 100;
glColor3f(0.6, 0.7, 0.8);
glRasterPos2f(300, 900);
for (w = 0; w < sizeof(wel); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, wel[w]);
glColor3f(0.5, 0.1, 0.7);
glRasterPos2f(200, 700);
for (w = 0; w < sizeof(start); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, start[w]);
glColor3f(0.7, 0.8, 0.9);
glRasterPos2f(200, 600);
for (w = 0; w < sizeof(controls); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, controls[w]);
glColor3f(0.2, 0.5, 0.7);
glRasterPos2f(200, 500);
for (w = 0; w < sizeof(levels); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, levels[w]);
glColor3f(1.0, 0.8, 0.3);
glRasterPos2f(200, 400);
for (w = 0; w < sizeof(about); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, about[w]);
glFlush();
}
}

The startmenu function handles the display of the start menu in the game. It checks the
values of dirFlag and upFlag to determine if any menu animation is required. If dirFlag is set
to 1, the menu items are shifted downwards by reducing the y-coordinates. On the other
hand, if upFlag is set to 1, the menu items are shifted upwards by increasing the y-
coordinates. The appropriate colors and positions are set using glColor3f and glRasterPos2f.
Catch Me

Text is then rendered using glutBitmapCharacter to display the menu options. Finally,
glFlush ensures that the drawing commands are executed.

Controls1()

void controls1() // function for controls window


{
glColor3f(0.56, 0.40, 0.8);
glRectf(0, 0, 1280, 1024);
glColor3f(0.3, 0.45, 0.76);
glRectf(20, 20, 1260, 1004);
glColor3f(0.0, 0.0, 0.0);
glRasterPos2f(100, 800);
for (w = 0; w < sizeof(control1); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, control1[w]);
glRasterPos2f(90, 700);
for (w = 0; w < sizeof(control2); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, control2[w]);
glRasterPos2f(100, 600);
for (w = 0; w < sizeof(control3); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, control3[w]);
glRasterPos2f(100, 500);
for (w = 0; w < sizeof(control4); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, control4[w]);
glRasterPos2f(100, 400);
for (w = 0; w < sizeof(control5); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, control5[w]);
glRasterPos2f(200, 300);
for (w = 0; w < sizeof(control6); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, control6[w]);
controlsFlag = 0;
glFlush();
}

The controls1 function is responsible for displaying the controls window in the game. It sets
the appropriate colors and draws rectangles to create the window background. Text is then
rendered using glRasterPos2f and glutBitmapCharacter functions to provide information
about the game controls. After displaying the controls, controlsFlag is reset to indicate that
Catch Me

the controls window is no longer active. Finally, glFlush ensures that all the drawing
commands are executed.

Lev()

void lev()
{
glColor3f(0.5, 0.5, 0.5);
glRectf(0, 0, 1280, 1024);
glColor3f(0, 0, 0);
glRasterPos2f(300, 800);
for (w = 0; w < sizeof(lev1); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, lev1[w]);
glRasterPos2f(300, 700);
for (w = 0; w < sizeof(lev2); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, lev2[w]);
glRasterPos2f(300, 600);
for (w = 0; w < sizeof(lev3); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, lev3[w]);
glRasterPos2f(300, 400);
for (w = 0; w < sizeof(lev5); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, lev5[w]);
glRasterPos2f(300, 500);
for (w = 0; w < sizeof(lev4); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, lev4[w]);
levFlag = 0;
glFlush();
}

The lev function is responsible for displaying the level selection window in the game. It sets
the appropriate colors and draws a rectangle to create the window background. Text is then
rendered using glRasterPos2f and glutBitmapCharacter functions to provide information
about the available levels. After displaying the level options, levFlag is reset to indicate that
the level selection window is no longer active. Finally, glFlush ensures that all the drawing
commands are executed.
Catch Me

cmr()

void cmr()
{
glColor3f(0, 0, 0);
glRectf(0, 0, 1280, 1024);

glColor3f(0.0, 0.7, 0.0); // text color


glRasterPos2f(520, 900);
for (w = 0; w < sizeof(cmr1); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cmr1[w]);
glColor3f(0.0, 0.5, 0.7); // text color
glRasterPos2f(420, 850);
for (w = 0; w < sizeof(cmr2); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cmr2[w]);
glColor3f(0.8, 0.0, 0.7); // text color
glRasterPos2f(370, 800);
for (w = 0; w < sizeof(cmr3); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cmr3[w]);
glColor3f(0.0, 0.0, 0.7); // text color
glBegin(GL_LINES);
glVertex2f(0, 700);
glVertex2f(1280, 700);
glEnd();
glRasterPos2f(580, 650);
// drawline
for (w = 0; w < sizeof(cmr4); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cmr4[w]);

glColor3f(0.8, 0.7, 0.0); // text color


glRasterPos2f(150, 600);
for (w = 0; w < sizeof(cmr5); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cmr5[w]);

glColor3f(0.8, 0.7, 0.0); // text color


glRasterPos2f(900, 600);
for (w = 0; w < sizeof(cmr6); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cmr6[w]);

glColor3f(0.0, 0.8, 0.0); // text color


glRasterPos2f(150, 550);
Catch Me

for (w = 0; w < sizeof(cmr7); w++)


glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cmr7[w]);

glColor3f(0.0, 0.8, 0.0); // text color


glRasterPos2f(150, 500);
for (w = 0; w < sizeof(cmr8); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cmr8[w]);

glColor3f(0.0, 0.8, 0.0); // text color


glRasterPos2f(900, 550);
for (w = 0; w < sizeof(cmr9); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cmr9[w]);

glColor3f(0.0, 0.8, 0.0); // text color


glRasterPos2f(900, 500);
for (w = 0; w < sizeof(cmr10); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cmr10[w]);

glColor3f(0.8, 0.8, 0.0); // text color


glRasterPos2f(550, 300);
for (w = 0; w < sizeof(cmr11); w++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cmr11[w]);

glFlush();
}

The cmr() function utilizes OpenGL commands to display concise information about the
project creators and their guides. It sets the background color, positions and renders text in
various colors, and draws a horizontal line. The function provides details about the
individuals involved in the project, facilitating recognition and acknowledgement of their
contributions.

3.3 Viewing
We have used a 2D orthographic projection for the game. It defines a viewing volume that
spans from coordinates (0, 0) in the bottom-left corner to (1280, 1024) in the top-right corner
of the window. This projection ensures that objects maintain a consistent size regardless of
Catch Me

their position in the game world, making it suitable for 2D rendering without perspective
distortion.

gluOrtho2D(0, 1280, 0, 1024);

3.4 Interactions
Mouse()

void mouse(int b, int s, int mx, int my)


{
x = mx;
y = wwh - my;
if (x >= o.x1 && x < o.x1 + 40 && y >= o.y1 && y <= o.y1 + 40)
{
hitFlag = 1;
messageTrue = 1;
}
glutPostRedisplay();
}

This function is a callback function triggered when a mouse button is pressed or released. It
updates the current mouse coordinates (mx and my) and adjusts the y-coordinate to match the
OpenGL window coordinates. The code then checks if the mouse is within the bounds of a
specific object (o). If the condition is met, it sets a flag (hitFlag) and displays a message
(messageTrue). Finally, it requests a redisplay of the scene using glutPostRedisplay() to
update the screen and reflect the changes caused by the mouse action.

Keyboard()
void keyboard(unsigned char key, int mx, int my)
{
if (key == '1')
startFlag = 1;
if (key == '2')
controlsFlag = 1;
if (key == '4')
aboutFlag = 1;
if (key == '3')
Catch Me

levFlag = 1;
if (key == 'a')
level1 = 1;
if (key ==
'b') level2 =
1;
if (key ==
'c') level3
= 1;
if (key == 13)
cmrFlag = 1;
glutPostRedisplay();
}

The keyboard function is a callback function that responds to keyboard input in the game.
When a key is pressed, it checks the value of key to determine which key was pressed. Based
on the key pressed, it updates different flags and variables in the game. For example, pressing
'1' sets the startFlag to 1, indicating that the game should start. Pressing 'a', 'b', or 'c' sets the
corresponding level variables (level1, level2, level3) to 1, indicating the selection of different
game levels. Pressing 'Enter' sets the cmrFlag to 1, triggering a specific action related to the
camera. Finally, it calls glutPostRedisplay() to notify the system that the display needs to be
redrawn to reflect the changes caused by the keyboard input.

3.5 Animation
moveRight()

void moveRight()
{
if (level1 == 0 && level2 == 0 && level3 == 0)
v = 5;
if (level1 == 1)
v = 5;
else if (level2 == 1)
v = 10;
else if (level3 == 1)
v = 15;
o.x1 = o.x1 + v;
o.y1 = o.y1;
Catch Me

o.x2 = o.x1 + 40;


o.y2 = o.y1 + 40;
glutPostRedisplay();
}

This function is responsible for moving the star towards the right direction. It updates the
star's position by incrementing its x-coordinate, allowing it to move horizontally across the
screen.
Catch Me

CHAPTER
4
RESULTS AND DISCUSSION
This section presents a collection of screenshots showcasing various screens of the game,
accompanied by descriptive explanations. This chapter serves to visually illustrate the
different aspects and features of the game, providing readers with a comprehensive
understanding of its graphical interface and gameplay elements. The screenshots and
descriptions contribute to the discussion by highlighting the visual aesthetics, user interface
design, and overall gameplay experience, fostering a deeper analysis and evaluation of the
game's performance and effectiveness.

4.1 Front Page

Fig 4.1 Frontpage

The front page image showcases the introductory section of the application, featuring
relevant information such as the institution's name, department, project title, and the names
of the creators and their guides.
Catch Me

4.2 Welcome Page

Fig 4.2 Startmenu

This screen, referred to as the start menu, displays a graphical user interface with various
options. It presents a menu layout featuring buttons for starting the game, accessing controls,
selecting levels, and obtaining information about the game. The menu design utilizes
different colors and font styles to enhance visual appeal and improve user experience. The
screen can be navigated using directional flags, allowing users to move up and down the
menu options.
Catch Me

4.3 How to play Page

Fig 4.3 How to play screen

This screen is a graphical interface that provides instructions and information about the game
controls. It features a visually appealing layout with colored rectangles as the background.
The page displays textual content explaining how to navigate and interact with the game. It
provides step-by-step instructions and guidelines to help users understand the controls and
gameplay mechanics. The information is presented in a clear and organized manner, making
it easy for players to learn how to play the game.
Catch Me

4.4 Levels Page

Fig 4.4 Screen to select level

This screen is a visually simple interface that allows players to choose different levels of the
game. The page displays a list of available levels along with their corresponding information
or names. Users can easily navigate through the options and select the desired level to play.
The textual content is presented in a clear and readable format, making it convenient for
players to make their selection.
Catch Me

4.5 Game Page

Fig 4.5 Game Screen

This screen is the main interface where the gameplay takes place. The background is colored,
providing visual contrast and separating the game area from the rest of the screen. The game
area is represented by a rectangular shape, filled with a different color, serving as the playing
field. The player's score is displayed at the top of the screen. The game involves interacting
with a moving object, represented by a star, using a point as a cursor. The objective is to hit
the moving object accurately. If the player successfully hits the object, they earn points, and a
"hit" message is displayed briefly. If the player misses the object, a "lost" message is
displayed, and the object is regenerated in a random position.
Catch Me

4.6 Game Over Page

Fig 4.6 Game Over Screen

The "Game Over Screen" is displayed when the game ends. The screen is filled with a
specific color, providing a distinctive background. The text "Game Over" is prominently
displayed at a specific position on the screen. Depending on the player's score, different
messages are shown. If the player's score is 100, a congratulatory message is displayed along
with the score. Otherwise, the player's score is shown, and if the score is 0, a message of
"hard luck" is displayed. The screen remains visible for a short duration before exiting the
game.
Catch Me

CHAPTER 5

CONCLUSION

In conclusion, we have developed a game implemented using OpenGL. Throughout the


project, we have gained valuable knowledge and experience in game development, graphics
programming, and user interface design. We have learned how to create interactive screens,
handle user input, and manage game logic.

One of the main challenges we faced during the project was managing the graphical
rendering and ensuring smooth gameplay. We had to optimize the code and balance
performance with visual appeal, constantly considering the best approach. Additionally,
implementing collision detection and scoring mechanisms presented some complexities that
required careful attention.

To further enhance the project, several additional functionalities could be incorporated.


Firstly, introducing power-ups or obstacles to interact with would add depth and variety to
the game. Implementing sound effects and background music would enhance the overall
immersion and enjoyment for the players.

Furthermore, incorporating a high-score leaderboard or a multiplayer mode would introduce


competitiveness and social interaction among players. Adding different game modes or
challenges, such as timed levels or puzzle elements, would provide additional layers of
gameplay complexity and excitement.

Overall, this project has allowed us to develop a game using OpenGL, learn valuable skills in
graphics programming, and overcome challenges in game development. With further
development, the game can be expanded with additional functionalities and features to make
it even more engaging and enjoyable for players.
REFERENCES

[1] Angel, Edward. Interactive Computer Graphics: A top-down approach with OpenGL.
Addison-Wesley Longman Publishing Co., Inc., 1996.
[2] Hearn, D., Baker, M. P., & Baker, M. P. (2004). Computer graphics with
OpenGL (Vol. 3). Upper Saddle River, NJ:: Pearson Prentice Hall.
[3] Set up Visual Studio Code
https://code.visualstudio.com/learn/get-started/basics

[4] How to Install OpenGL in Ubuntu in WSL2


https://gist.github.com/Mluckydwyer/8df7782b1a6a040e5d01305222149f3c
Catch Me

Appendix A
Installation
1. Install WSL2
 Ensure that you have Windows 10 version 2004 or later with WSL2 support. You can
check this by running wsl -l -v in the Windows Command Prompt or PowerShell.
 Enable the Windows Subsystem for Linux (WSL) feature. Open PowerShell as
Administrator and run the following command:
wsl –install

2. Install a Linux distribution:


 Open the Microsoft Store and search for a Linux distribution of your choice, such as
Ubuntu or Debian.
 Select the desired distribution and click "Get" or "Install" to download and install it.
 Launch the Linux distribution from the Start menu and follow the on-screen
instructions to set up a user account.

3. Install Visual Studio Code:


 Open a web browser and go to the Visual Studio Code website:
https://code.visualstudio.com/
 Download the appropriate version of VS Code for Windows.
 Run the installer and follow the on-screen instructions to complete the installation.

4. Install the Remote - WSL extension in VS Code:


 Launch Visual Studio Code.
 Open the Extensions view by clicking on the square icon on the left sidebar or
pressing Ctrl+Shift+X.
 Search for "Remote - WSL" in the Extensions view.
 Click on the "Remote - WSL" extension by Microsoft and click the Install button.
 Once installed, click the Reload button to activate the extension.

Dept. of CSE, CMRIT, Bengaluru. 2022 - 23 Page 32


Catch Me

5. Configure WSL in VS Code:


 Open the Command Palette in VS Code by pressing Ctrl+Shift+P.
 Type "WSL: New WSL Window" and select it from the list to open a new VS Code
window connected to your WSL2 instance.

6. Install OpenGL on WSL2:


 Open the WSL2 terminal in VS Code or launch the Linux distribution from the Start
menu.
 Update the package list by running:
sudo apt update
 Install the required OpenGL packages by running:
sudo apt install libgl1-mesa-dev
 The installation process will download and install the necessary packages for
OpenGL development on WSL2.

7. Verify OpenGL installation:


 You can test your OpenGL installation by compiling and running a simple OpenGL
program.

Dept. of CSE, CMRIT, Bengaluru. 2022 - 23 Page 33


Catch Me

Appendix B
OpenGL Functions
 void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
GLdouble nearVal, GLdouble farVal)
 void glBegin(GLenum mode)
 void glEnd(void)
 void glVertex2f(GLfloat x, GLfloat y)
 void glClear(GLbitfield mask)
 void glColor3f(GLfloat red, GLfloat green, GLfloat blue)
 void glRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
 void glRasterPos2f(GLfloat x, GLfloat y)
 void glutBitmapCharacter(void *font, int character)
 void glFlush(void)
 void gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
 void glMatrixMode(GLenum mode)
 void glLoadIdentity(void)
 void glPointSize(GLfloat size)
 void glBegin(GLenum mode)
 void glEnd(void)
 void glVertex2f(GLfloat x, GLfloat y)
 void glutPostRedisplay(void)

Dept. of CSE, CMRIT, Bengaluru. 2022 - 23 Page 34

You might also like