SlideShare a Scribd company logo
VISVESVARAYA TECHNOLOGICAL UNIVERSITY
BELGAUM-590 014
A Mini-Project Report
on
Ping Pong Ball Game
Submitted in partial fulfillment of the requirement for the award of the degree of
BACHELOR OF ENGINEERING
in
COMPUTER SCIENCE AND ENGINEERING
Submitted by
SARABJEET SINGH, 1VE20CS141
SUHAS S, 1VE20CS152
Under the Guidance of
Mrs. Kulkarni Varsha
Assistant Professor
Department of Computer Science and Engineering
Sri Venkateshwara College of Engineering, Bangalore-562 157
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
SRI VENKATESHWARA COLLEGE OF ENGINEERING
BANGALORE - 562 157
2022-2023
SRI VENKATESHWARA COLLEGE OF ENGINEERING,
Vidyanagar, Bangalore – 562 157
Department of Computer Science and Engineering
CERTIFICATE
This is to certify that the Mini-Project entitled “PING PONG BALL GAME” carried out by
Mr SUHAS S - USN 1VE20CS152 Mr SARABJEET SINGH - USN 1VE20CS141 of VI
Semester students of Sri Venkateshwara College of Engineering, in partial fulfillment for the award
of Bachelor of Engineering in Computer Science and Engineering of Visvesvaraya Technological
University, Belgaum during the academic year 2022-2023. The Mini-Project report has been
approved as it satisfies the academic requirements in respect of Computer Graphics and
Visualization Laboratory with Mini-Project (18CSL67) work prescribed for the said Degree.
Name of the Examiners: Signature with Date
1.
2.
Signature of the Guide
Mrs. Kulkarni Varsha
Asst. Professor, Dept. of CS&E
SVCE, Bangalore
Signature of the HOD
Dr. Hema M S
HOD, Dept. of CS&E
SVCE, Bangalore
ACKNOWLEDGEMENT
The satisfaction and euphoria that accompany the successful completion of any task would be
incomplete without complementing those who made it possible, whose guidance and
encouragement made our efforts successful.
We would like to express my sincere gratitude to the highly esteemed institution SRI
VENKATESHWARA COLLEGE OF ENGINEERING. The institution is providing me the
knowledge to become a software engineer.
We express my sincere gratitude to Dr. NAGESWARA GUPTHA M, Principal,
SVCE,Bengaluru for providing the required facility.
We are extremely thankful to Dr. HEMA M S, HOD of CSE, SVCE, for providing the support
andencouragement.
We are grateful to Mrs. KULKARNI VARSHA, Ms. RASHMI J, Asst. Professor, Dept of
CSE, SVCE who helped me to complete this project successfully by providing guidance,
encouragement and valuable suggestion during the entire period of the project. I thank all the
information science staff andothers who helped me directly or indirectly to meet my project
work with grand success.
Finally I am grateful to my parents and friends for their invaluable support, guidance and
encouragement.
SARABJEET SINGH 1VE20CS141
SUHAS S 1VE20CS152
ABSTRACT
This abstract presents a single-player 2D Ping Pong Ball Game developed using OpenGL, a
powerful graphics library. The game offers a classic arcade experience, where the player
controls a paddle to hit a ball back.
The game utilizes OpenGL's capabilities to create a visually appealing environment with
smooth animations, accurate collision detection, and vibrant colors. The player's objective is
to score points by successfully hitting the ball past the opponent's paddle while avoiding
missing the ball themselves.
The game showcases the versatility of OpenGL in rendering 2D graphics and highlights its
compatibility with various programming languages. With its engaging gameplay, responsive
controls, and immersive experience, the single-player 2D Ping Pong Ball Game provides
entertainment and a chance to test one's skills in a virtual ping pong match.
TABLE OF CONTENTS
1. INTRODUCTION 1-6
1.1 GLUT
1.2 HOW OPENGL WORKS
1.3 OPENGL
1.4 PROJECT INTRODUCTION
2. SYSTEM REQUIREMENT 7
2.1 SOFTWARE REQUIREMENT
2.2 HARDWARE REQUIREMENT
3. PROJECT DESIGN 8-9
3.1 PURPOSE
3.2 DESCRIPTION
3.3 FLOW CHART
4. IMPLEMENTATION 10-16
4.1 ATTRIBUTES
4.2 WORKING WITH THE WINDOW SYSTEM
4.3 INTERACTION
4.4 TRANSFORMATION
4.5 VIEWING
4.6 SOURCE CODE
5. SNAPSHOTS 17
6. TESTING 18
CONCLUSIONS
FUTURE ENHANCEMENT
REFERENCES
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 1
Chapter 1
INTRODUCTION
The dominant characteristics of this new computer and communication technologies have
become dominant forces in our life. Activities as wide ranging as filmmaking, publishing,
banking and education continue to undergo revolutionary changes as these technologies alter
the ways in which we conduct our daily activities. The combination of computers , networks,
and the complex visual system, through the computer graphics has led to new way of displaying
information, seeing virtual worlds and communicating with people and machines.
Computer graphics is concerned with all aspects of producing pictures or images using a
computer. The field has begun humbly almost 50 years ago, with a display of few lines on a
cathode ray tube, now we can create images by computer that are indistinguishable from
photographs of real objects. We routinely train pilots with simulated airplanes, generating
graphical displays of virtual environment of real time. Feature length movies made entirely by
computer have been successful, both critically and financially. Massive multiplayer games can
involve tens of thousands of concurrent participants.
1.1 GLUT:
It is complete API written by mark kilogram, which lets us create windows and handle the
messages. It exists for several platforms that a program, which uses GLUT, can be compiled
on many platforms without any changes in the code.
ADDITONAL LIBRARIES:
There are two libraries functions that we have learnt in OpenGL.
1 .glu :It is a set of utility functions, they are easy way of doing things that is tedious with raw
OpenGL.
2. glx :It allows you to open up X window and link it up with OpenGL so that it will draw to
that window.
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 2
1.2 HOW OpenGL WORKS?
To be hardware independent OpenGL provides its own data types, they all begin with “GL”.
Eg: GLfloat, Glint. There are also many symbolic constants that all begin with ”GL”. Eg:
GL_POINTS, GL_LINES. Finally commands have prefix ”gl”. Eg: glVertex3f (f, i, d).
There are utility library called as “GLU”. Here the prefixes are “GLU_”, ”glu”. GLUT
commands begin with “glut” it is same for every library. OpenGL is a widely accepted standard
for developing graphics applications. Fortunately, OpenGL is easy to learn and it possesses
most of the characteristics of other graphics systems. Graphics API’s such as OpenGL,
developed as a way to provide application programmers with the access to hardware features
that were being provided by the latest graphics hardware.
Application of Computer Graphics:
The development of computer graphics has been driven both by needs of the user community
and by advancement in technology. The applications of computer graphics of computer
graphics are many and varied, we can divide them into four categories :
1. Display of information
2. Design
3. Simulation and Animation
4. User interface
1. Display of Information:
Medical imaging possess interesting and important data analysis problem. Modern imaging
technologies such as computed tomography (CT), magnetic resonance imaging(MRI),
ultrasound, and position emission tomography(PET), generate 3D data that must be subjected
to algorithmic manipulation to provide useful information.
The field of scientific visualization provides graphical tools that help the researchers interpret
the fast quantity of data that generate.
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 3
2. Design:
Professions such as engineering and architecture are concerned with design. Starting with a set
of specifications, engineers and architects seek a cost effective and esthetical solution that
satisfies the specifications.
Design is an interactive process. Design problem are either over determined such that they
possess no solution that satisfies all criteria, much less an optimal solution, or undetermined,
such that they have multiple solutions that satisfies the design criteria.
3. Simulation and Animation:
Graphics system evolved to be capable of generating sophisticated images in real time,
engineers and researchers began to use them as simulators. One of the most important use has
been in training of pilots. The use of special PLSI chips has led to a generation of arcade, games
as sophisticated as flight simulators.
The simulators can be used for designing the robot, planning its path, and simulating its
behaviour in complex environment. The success of flight simulators led to the use of computer
graphics for animation in TV, motion pictures and advertising industries. Entire animated
movies can now be made by computers at a cost less than that of movies made with traditional
ways.
4.User interface:
Our interaction with computers has become dominated by visual paradigm that includes icons,
menus and pointing devices such as mouse. From users perspectives, winding system such as
X and window system, Microsoft windows.
1.3 OPENGL:
• Graphics rendering API.
• High Quality colour images composed of geometric primitives
• Operating system independent
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 4
• OpenGL is an application programmer’s interface (API) that allows programmers to
write programs that access graphics hardware.
OpenGL provide a set of commands to render a two dimensional scene. That means you
provide data in OpenGL usable form and OpenGL will show you this data in scene (render it).it
is developed by many companies and it is free for use. You can develop OpenGL applications
without licensing.
OpenGL based on the state variables, there are many values for example, the colour, you can
specify a colour once and draw several polygons, lines and whatever you want. Then there are
no classes like in directX. However it is logically structured. Before we come to the commands
themselves, here are another thing.
To be hardware independent, OpenGL provides its own data types . They all begin with “GL”.
For ex: GLfloat, GLint and so on. There are also many symbolic constants; they all begin with
“GL” for ex: GL_POINTS, GL_LINES. Finally the commands have the prefix “gl”. There is
utility library called GLU, here the prefixes are “GLU” & “glu”. It is same for every library.
You want to know which library coexist with the one called before. There are libraries for every
system. Windows as the wgl*functions, UNIX system glx* and so on.
It is very important thing to know, that there are two important matrices, which affect the
transformation from 3D world to 2D screen. The projection matrix and the model view matrix.
The projection matrix contains information, how a vertex can be mapped tom the screen. This
contains, whether the projection shall be isometric or a form of perspective, how wide the field
of view is and so on. Into the other matrix you put information, how the objects are moved,
where the viewer is and so on.
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 5
The OpenGL pipeline:
Fig1.3.1: the OpenGL rendering pipeline
Commands may be either be accumulated in display lists are processed immediately through
pipeline architecture. Display lists allow for greater optimization and command reuse, but not
all commands can be put in display lists.
The first stage is evaluator. This stage effectively takes any polynomial evaluator commands
and evaluates them into their corresponding vertex and attributes commands
The second stage is per-vertex operations, including transformations, lighting, primitive
assembly, clipping, projection, and viewport mapping. The third stage is rasterization. This
stage produces fragments, which are series of frame buffer address and values from the
viewport mapped primitives as well as bitmaps and pixel rectangles.
The fourth stage is the per-fragment operations. Before fragments go to the frame buffer, they
may subjected to a series of conditional tests and modifications, such as blending or Z-
buffering.
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 6
1.4 PROJECT INTRODUCTION
Introduction to Ping Pong Ball Game using OpenGL
The Ping Pong Ball Game implemented using OpenGL is a simple yet entertaining 2D
arcade game. It recreates the popular table tennis sport.In this game, the players aim to score
points by successfully hitting the ball past their opponent's paddle. The game utilizes OpenGL,
a powerful graphics library, to render the game elements and create an immersive visual
experienceThe game environment consists of a rectangular playfield representing the ping pong
table. Each player controls a paddle, which is a rectangular shape on their side of the table. The
ball, represented by a small circular shape, moves dynamically across the playfield.
The game employs OpenGL's capabilities to handle graphics rendering, animation, and
collision detection. It ensures smooth movement of the ball and paddles, allowing for realistic
gameplay. The collision detection mechanism determines when the ball contacts the paddles,
walls, or other game objects, enabling appropriate reactions such as bouncing the ball off the
paddles.Additionally, the game keeps track of the players' scores, incrementing them whenever
a player fails to return the ball successfully. The game typically ends when one player reaches
a predetermined score or after a fixed duration of play.
Overall, the Ping Pong Ball Game project demonstrates the power of OpenGL in
creating an engaging and interactive gaming experience. By simulating the dynamics of table
tennis, it provides an enjoyable challenge for players. Through the combination of keyboard
controls, smooth graphics, and accurate collision detection, this project showcases the potential
of OpenGL in developing 2D games.
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 7
Chapter 2
SYSTEM REQUIREMENTS
2.1 Software Requirements:
• An MS_DOS based operating system like windows XP
• Avisual C/C++ compiler is required for compiling the source code to make a executable
file which can be directly executed
• The built in graphics and dynamic link libraries like glut and glut32, and header file
like glut.h to create 2D &3D layout.
2.2 Hardware Requirements:
• Processor : intel 486/Pentium processor and above
• Processor speed : 500MHz or above
• RAM : 64 MB or above
• Storage space : 50 MB or above
• Monitor Resolution : colour monitor with minimum resolution of 640*480
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 8
Chapter 3
PROJECT DESIGN
3.1 PURPOSE
Demonstration of simulation of 2D Ping Pong Ball Game .
3.2 DESCRIPTION
The player can control their respective paddles using keyboard inputs. The
specific keys use for control can vary, but typically they are assigned to the left and right
direction using 'B' and 'N' keys. By pressing the designated keys, the player can move their
paddles left and right, attempting to intercept the ball.
The game environment consists of a rectangular playfield representing the ping pong
table. Player controls a paddle, which is a rectangular shape on their side of the table. The ball,
represented by a small circular shape, moves dynamically across the playfield.
Additionally, the game keeps track of the player score, incrementing them whenever a
player fails to return the ball successfully. The game typically ends when one player reaches a
predetermined score or after a fixed duration of play. But there is a condition to this game ,if
the player moves the paddle to the extreme left the player is disqualified.
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 9
2.3 FLOW CHART
if paddle = extreme left
Fig2.3.1: Flowchart for Simulation of 3D Windmill
START
MAIN
INITIALIZE CALLBACK FUNCTIONS
STOP
MAIN SCREEN DISPLAYED
Keyboard
‘N’ for right
‘B’ for left
EVENTS
‘Q’ for exit
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 10
Chapter 4
IMPLEMENTATION
This program has been developed and implemented using OpenGL interface. In
corporate this facility includes glut.h header files.
• Void glBegin(glEnum mode)
Initiates a new primitive of mode and starts the collection of vertices. Values of mode include
GL_POITS, GL_LINES and GL_POLYGON.
• Void glEnd()
Terminates a list of vertices.
4.1 Attributes
➢ Void glColor3[b I f d ub us ui](TYPE r, TYPE g, TYPE b)
Sets the present RGB colors. Valid types are byte(b),int (i), float (f), double (d), unsigned
byte(ub), unsigned short(us) and unsigned int (ui).
1. Void glClearColor(GLclampfg,Glclampfg,Glclampfb, Glclampfa)
Sets the present RGBA clear color used when clearing the color buffer. Variable of Glclampf
are floating point numbers between 0.0 and1.0.
2. Void glPointSize(Glfloat size)
Sets the point size attribute in pixels.
4.2 Working with the window system
➢ Void glFlush()
Forces any buffered openGL commands to execute.
➢ Void glutInit(int argc, char **argv)
Initializes GLUT. The arguments from main are passed in and can be used by the application.
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 11
➢ Void glutCreateWindow(char*title)
Creates a window on the display. The string title can be used by the window. The return value
provides reference to the windows that can be used when there are multiple windows.
➢ void glutInitDisplayMode(unsigned int mode)
Requests a display with the properties in mode. The value of mode is determined by the logical
OR of options including the colormodel(GLUT_RGB, GLUT_INDEX) and buffering
(GLUT_SINGLE,GLUT_DOUBLE).
➢ void glutInitWindowSize(intwidth,int height)
Specifies the initial height and width of the window in pixels.
➢ void glutInitWindowPosition(intx,int y)
Specifies the initial position of top-left corner of the window in pixels.
➢ void glViewport(intx,inty,Glsizei height)
Specifies a width x height viewport in pixels whose lower left corner is at(x,y) Measured from
origin of the window.
➢ void glutMainLoop()
Causes the program to enter an event processing loop. It should be the lat statement in main.
➢ Void glutDisplayFunc(void(*func)(void))
Requests that the display callback be executed after the current callback returns.
➢ void glutSwapBuffers()
Swaps the front and back buffers.
4.3 Interaction
➢ Void glutKeyboardFunc(void *f(char key,intwidth,int height)
Register the keyboard callbackfunc f. The callback function returns the ASCII ode of
the key pressed and the position of the mouse.
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 12
➢ Void glutIdleFunc(void (*f)(void))
Registers the display callback function f that is executed whenever there are no other
events to be handled.
4.4 Transformation
➢ void glMatrixmode(Glenum mode)
Specifies which matrix will be affected by subsequent transactions. Mode can be
GL_MODEL_VIEW,GL_PROJECTION or GL_TEXTURES.
➢ Void glLoadIdentity()
Sets the current transformation matrix to an identity matrix.
➢ void glTranslate[fd](TYPE x, TYPE y, TYPE z)
Alters the current matrix by a displacement of(x,y,z). TYPE is of either Glfloat or
Gldouble.
➢ Void glScale[fd]](TYPE x, TYPE y, TYPE z)
Alters the current matrix by scaling of(sx,sy,sz). TYPE is either Glfloat or Gldouble.
4.5 Viewing
➢ Void glOrtho2D(Gldoubleleft,Gldoubleright,Gldoublebottom,Gldouble top)
Defines a two dimentional viewing rectangle in the planes z=0.
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 13
4.7 SOURCE CODE
// C program to illustrate OpenGL game
#include <stdio.h>
#include <GL/glut.h>
#include <math.h>
#include <unistd.h>
//for WINDOWS run use below library
//#include<windows.h>
#define pi 3.142857
// Global Declaration
// c and d tracks the number of time 'b' and 'n' pressed respectively
// left and right indicates leftmost and rightmost index of movable rectangle
int c = 0, d = 0, left = 0, right = 0;
int m = 0, j = 1, flag1 = 0, l = 1, flag2 = 0, n = 0, score = 0, count = 1;
// Initialization function
void myInit(void)
{
sleep(1);
// Reset background color with white (since all three argument is 1.0)
glClearColor(1.0, 0.0, 0.0, 0.0);
// Set picture color to red (in RGB model)
// as only argument corresponding to R (Red) is 1.0 and rest are 0.0
glColor3f(1.0f, 0.0f, 0.0f);
// Set width of point to one unit
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set window size in X- and Y- direction
gluOrtho2D(-620.0, 620.0, -340.0, 340.0);
}
// keyboard function : it gets active when button pressed
void keyboard(unsigned char key, int x, int y)
{
left = -200 + 200 * (d - c);
right = 200 + 200 * (d - c);
// if leftmost index of window is hit
// then rectangle will not move to left on further pressing of b
// only it will move to right on pressing n
if (left == -600)
{
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 14
// '110' -> Ascii value of 'n'
// so d is incremented when n is pressed
if (key == 100)
d++;
}
// if rightmost index of window is hit
// then rectangle will not move to right on further pressing of n
// only it will move to left on pressing b
else if (right == 600)
{
// '98' -> Ascii value of 'b'
// so c is incremented when b is pressed
if (key == 98)
c++;
}
// when rectangle is in middle, then it will move into both
// direction depending upon pressed key
else
{
if (key == 98)
c++;
if (key == 110)
d++;
}
glutPostRedisplay();
}
void myDisplay(void)
{
// x and y keeps point on circumference of circle
int x, y, k;
// outer 'for loop' is to for making motion in ball
for (k = 0; k <= 400; k += 5)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE_STRIP);
// i keeps track of angle
float i = 0;
// change in m denotes motion in vertical direction and
// change in n denotes motion in horizontal direction
m = m + 6;
n = n + 4;
// drawing of circle centre at (0, 12) iterated up to 2*pi, i.e., 360 degree
while (i <= 2 * pi)
{
y = 12 + 20 * cos(i);
x = 20 * sin(i);
i = i + 0.1;
// flag1 is 0 to show motion in upward direction and is 1 for downward direction
if (m == 288 && flag1 == 0)
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 15
{
j = -1;
m = -288;
flag1 = 1;
score++;
}
if (m == 288 && flag1 == 1)
{
j = 1;
m = -288;
flag1 = 0;
}
// flag2 is 0 to show motion in rightward direction and is 1 for leftward direction
if (n == 580 && flag2 == 0)
{
l = -1;
n = -580;
flag2 = 1;
}
if (n == 580 && flag2 == 1)
{
l = 1;
n = -580;
flag2 = 0;
}
// equation for desired motion of ball
glVertex2i((x - l * n), (y - j * m));
}
glEnd();
// these four points draws outer rectangle which determines window
glBegin(GL_LINE_LOOP);
glVertex2i(-600, -320);
glVertex2i(-600, 320);
glVertex2i(600, 320);
glVertex2i(600, -320);
glEnd();
// these four points draws smaller rectangle which is for catching ball
glBegin(GL_LINE_LOOP);
left = -200 + 200 * (d - c);
right = 200 + 200 * (d - c);
glVertex2i(left, -315);
glVertex2i(left, -295);
glVertex2i(right, -295);
glVertex2i(right, -315);
glEnd();
// following condition checks if falling ball is catched on rectangle or not
if ((j * m) == 276)
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 16
{
if ((left > ((-1 * l * n) + 20)) || (right < (-1 * l * n) - 20))
{
printf("Game Over !!!nYour Score is :t%dn", score);
exit(0);
}
}
glutSwapBuffers();
}
}
// Driver Program
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
// Declares window size
glutInitWindowSize(1100, 600);
// Declares window position which is (0, 0)
// means lower left corner will indicate position (0, 0)
glutInitWindowPosition(50, 50);
// Name to window
glutCreateWindow("Game");
// keyboard function
glutKeyboardFunc(keyboard);
// Call to myInit()
myInit();
glutDisplayFunc(myDisplay);
glutMainLoop();
}
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 17
Chapter 5
SNAPSHOTS
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 18
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 19
Chapter 6
TESTING
6.1 TESTING
Software testing is a critical element of the ultimate review of specification design and
coding. Testing of software leads to the uncovering of errors in the software functional and
performance requirements are met. Testing also provides a good indication of software
reliability and software quality as a whole. The result of different phases of testing are evaluated
and then compared with the expected results. If the errors are uncovered they are debugged and
corrected. A strategy approach to software testing has the generic characteristics:
• Different testing techniques are appropriate at different points of time.
• Testing and debugging are different activities, but debugging must be accommodated
in the testing strategy.
Following three approaches of debugging were used:
o Debugging by Induction
o Debugging by Deduction
o Backtracking
6.2 TEST PLANS
In this test plan all major activities are described below:
• Unit testing.
• Integration testing.
• Validation testing.
• System testing.
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 20
Table 5.3: Test case for keyboard
SL.no Test case
descrip-
tion
Expected
result
Actual
result
Remarks
1. Press Enter
to start
game
Will start
the game
Will start
the game
PASS
2. Press B for
left
Move the
pebble
left
Move the
pebble left
PASS
3. Press N for
right
Move the
pebble
right
Move the
pebble
right
PASS
4. Press Q for
exit
Exit the
game
Exit the
game
PASS
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 21
CONCLUSIONS
In conclusion, the development of a single-player 2D Ping Pong Ball Game using OpenGL has
resulted in a captivating and enjoyable gaming experience. The integration of OpenGL's
graphics capabilities has allowed for the creation of a visually appealing game environment.
By controlling a paddle and interacting with the ball, players can relish the excitement and
challenges of a classic ping pong game in a virtual setting. The game's implementation of
responsive controls, smooth animations, and accurate collision detection contributes to a
realistic and immersive gameplay experience.
The utilization of 2D elements such as the paddles, ball, and playfield brings the game to life
and creates an engaging atmosphere.
Moreover, the project highlights the versatility of OpenGL as a graphics library and its
compatibility with various programming languages. The seamless integration of OpenGL with
the game's logic allows for efficient rendering and optimized performance.
In summary, the single-player 2D Ping Pong Ball Game developed using OpenGL delivers an
immersive and entertaining gaming experience.
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 22
FUTURE ENHANCEMENT
This project has been designed using C, which works on the windows platform. The project
can be designed using other languages and better graphical interfaces. The following features
could have been incorporated.
✓ Enabling multiplayer functionality.
✓ In window interaction.
✓ Enabling score board in GUI in window.
Ping Pong Game
DEPT OF CSE, SVCE 2022-2023 Page 23
REFERENCES
BIBLIOGRAPHY
[1] Edward Angel’s Interactive Computer Graphics Pearson Education 5th
Edition
[2] Interactive computer Graphics - A top down approach using open GL by Edward Angel
[3] Jackie L.Neider,Mark Warhol, Tom R.Davis,"OpenGL Red Book", Second Revised
Edition,2005.
[4] Donald D Hearn and M.PaulineBaker,"Computer Graphics with OpenGL",3rd
Edition.
WEBSITES
[5] www.OpenGLRedbook.com
[6] www.OpenGLsimpleexamples.com

More Related Content

PDF
Code Of Ethical Business Conduct Mandate
Yashveer Singh
 
PDF
Top Effective Digital Marketing Strategies for Astrologers
IntegrityWeb Informatics Pvt. Ltd.
 
PDF
CGV Project Report.pdf
HimaBindhu41
 
PDF
bhargav_flowing-fountain
Bhargav K. Naidu
 
PDF
CG mini project
Mohammed Dawood
 
PDF
TICTACTOE GAME MANAGEMENT SYSTEM PROJECT REPORT.
Kamal Acharya
 
PDF
Ball Collecting game report
Dileep Maurya
 
PDF
Bachelors project
Ganesh Grandhi
 
Code Of Ethical Business Conduct Mandate
Yashveer Singh
 
Top Effective Digital Marketing Strategies for Astrologers
IntegrityWeb Informatics Pvt. Ltd.
 
CGV Project Report.pdf
HimaBindhu41
 
bhargav_flowing-fountain
Bhargav K. Naidu
 
CG mini project
Mohammed Dawood
 
TICTACTOE GAME MANAGEMENT SYSTEM PROJECT REPORT.
Kamal Acharya
 
Ball Collecting game report
Dileep Maurya
 
Bachelors project
Ganesh Grandhi
 

Similar to CG_report_merged (1).pdf (20)

PDF
Tictactoe game management system project report.pdf
Kamal Acharya
 
PDF
Computer graphics by bahadar sher
university of Malakand Dir Lower
 
PDF
Minor Project Synopsis on Data Structure Visualizer
RonitShrivastava057
 
PDF
AIR WRITING USING PYTHON (2021-2022)
IRJET Journal
 
DOCX
ARDUINO EMBEDDED SYSTEM
Vishal GARG
 
PPTX
Technical Seminar ppt final for everyone.pptx
MohitMht1
 
PDF
Squid Game and Music Synchronization
IRJET Journal
 
PDF
Sample projectdocumentation
hlksd
 
PPTX
Technical Seminar ppt ey eveyryoneee.pptx
MohitMht1
 
PDF
ARTIFICIAL INTELLIGENCE DESKTOP VOICE ASSISTANT IN PYTHON
IRJET Journal
 
DOC
Nanaji_Sahukara
Nanaji Sahukara
 
PPTX
Final1.pptx hbhnnhhhh bnbnbhhbhbbbbbbbbbbb
DnyaneshwarPrathames
 
PDF
Industrial training report
Priyanshu
 
DOCX
Barcode Verification Dct.docx
hrutikaghodke1
 
PDF
FIRST PERSON SHOOTER GAME UNITY 3D
Rohith GS
 
PDF
Sikuli script
Snehal Patel
 
PDF
Car Game Final Year Project
Bithika Barik
 
PDF
Car Game - Final Year Project
Vivek Naskar
 
PDF
Google Developer Student Club Avantika University Info Session
AKSHATPATEL48
 
PDF
FACE COUNTING USING OPEN CV & PYTHON FOR ANALYZING UNUSUAL EVENTS IN CROWDS
IRJET Journal
 
Tictactoe game management system project report.pdf
Kamal Acharya
 
Computer graphics by bahadar sher
university of Malakand Dir Lower
 
Minor Project Synopsis on Data Structure Visualizer
RonitShrivastava057
 
AIR WRITING USING PYTHON (2021-2022)
IRJET Journal
 
ARDUINO EMBEDDED SYSTEM
Vishal GARG
 
Technical Seminar ppt final for everyone.pptx
MohitMht1
 
Squid Game and Music Synchronization
IRJET Journal
 
Sample projectdocumentation
hlksd
 
Technical Seminar ppt ey eveyryoneee.pptx
MohitMht1
 
ARTIFICIAL INTELLIGENCE DESKTOP VOICE ASSISTANT IN PYTHON
IRJET Journal
 
Nanaji_Sahukara
Nanaji Sahukara
 
Final1.pptx hbhnnhhhh bnbnbhhbhbbbbbbbbbbb
DnyaneshwarPrathames
 
Industrial training report
Priyanshu
 
Barcode Verification Dct.docx
hrutikaghodke1
 
FIRST PERSON SHOOTER GAME UNITY 3D
Rohith GS
 
Sikuli script
Snehal Patel
 
Car Game Final Year Project
Bithika Barik
 
Car Game - Final Year Project
Vivek Naskar
 
Google Developer Student Club Avantika University Info Session
AKSHATPATEL48
 
FACE COUNTING USING OPEN CV & PYTHON FOR ANALYZING UNUSUAL EVENTS IN CROWDS
IRJET Journal
 
Ad

Recently uploaded (20)

PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
CDH. pptx
AneetaSharma15
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
CDH. pptx
AneetaSharma15
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
Ad

CG_report_merged (1).pdf

  • 1. VISVESVARAYA TECHNOLOGICAL UNIVERSITY BELGAUM-590 014 A Mini-Project Report on Ping Pong Ball Game Submitted in partial fulfillment of the requirement for the award of the degree of BACHELOR OF ENGINEERING in COMPUTER SCIENCE AND ENGINEERING Submitted by SARABJEET SINGH, 1VE20CS141 SUHAS S, 1VE20CS152 Under the Guidance of Mrs. Kulkarni Varsha Assistant Professor Department of Computer Science and Engineering Sri Venkateshwara College of Engineering, Bangalore-562 157 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING SRI VENKATESHWARA COLLEGE OF ENGINEERING BANGALORE - 562 157 2022-2023
  • 2. SRI VENKATESHWARA COLLEGE OF ENGINEERING, Vidyanagar, Bangalore – 562 157 Department of Computer Science and Engineering CERTIFICATE This is to certify that the Mini-Project entitled “PING PONG BALL GAME” carried out by Mr SUHAS S - USN 1VE20CS152 Mr SARABJEET SINGH - USN 1VE20CS141 of VI Semester students of Sri Venkateshwara College of Engineering, in partial fulfillment for the award of Bachelor of Engineering in Computer Science and Engineering of Visvesvaraya Technological University, Belgaum during the academic year 2022-2023. The Mini-Project report has been approved as it satisfies the academic requirements in respect of Computer Graphics and Visualization Laboratory with Mini-Project (18CSL67) work prescribed for the said Degree. Name of the Examiners: Signature with Date 1. 2. Signature of the Guide Mrs. Kulkarni Varsha Asst. Professor, Dept. of CS&E SVCE, Bangalore Signature of the HOD Dr. Hema M S HOD, Dept. of CS&E SVCE, Bangalore
  • 3. ACKNOWLEDGEMENT The satisfaction and euphoria that accompany the successful completion of any task would be incomplete without complementing those who made it possible, whose guidance and encouragement made our efforts successful. We would like to express my sincere gratitude to the highly esteemed institution SRI VENKATESHWARA COLLEGE OF ENGINEERING. The institution is providing me the knowledge to become a software engineer. We express my sincere gratitude to Dr. NAGESWARA GUPTHA M, Principal, SVCE,Bengaluru for providing the required facility. We are extremely thankful to Dr. HEMA M S, HOD of CSE, SVCE, for providing the support andencouragement. We are grateful to Mrs. KULKARNI VARSHA, Ms. RASHMI J, Asst. Professor, Dept of CSE, SVCE who helped me to complete this project successfully by providing guidance, encouragement and valuable suggestion during the entire period of the project. I thank all the information science staff andothers who helped me directly or indirectly to meet my project work with grand success. Finally I am grateful to my parents and friends for their invaluable support, guidance and encouragement. SARABJEET SINGH 1VE20CS141 SUHAS S 1VE20CS152
  • 4. ABSTRACT This abstract presents a single-player 2D Ping Pong Ball Game developed using OpenGL, a powerful graphics library. The game offers a classic arcade experience, where the player controls a paddle to hit a ball back. The game utilizes OpenGL's capabilities to create a visually appealing environment with smooth animations, accurate collision detection, and vibrant colors. The player's objective is to score points by successfully hitting the ball past the opponent's paddle while avoiding missing the ball themselves. The game showcases the versatility of OpenGL in rendering 2D graphics and highlights its compatibility with various programming languages. With its engaging gameplay, responsive controls, and immersive experience, the single-player 2D Ping Pong Ball Game provides entertainment and a chance to test one's skills in a virtual ping pong match.
  • 5. TABLE OF CONTENTS 1. INTRODUCTION 1-6 1.1 GLUT 1.2 HOW OPENGL WORKS 1.3 OPENGL 1.4 PROJECT INTRODUCTION 2. SYSTEM REQUIREMENT 7 2.1 SOFTWARE REQUIREMENT 2.2 HARDWARE REQUIREMENT 3. PROJECT DESIGN 8-9 3.1 PURPOSE 3.2 DESCRIPTION 3.3 FLOW CHART 4. IMPLEMENTATION 10-16 4.1 ATTRIBUTES 4.2 WORKING WITH THE WINDOW SYSTEM 4.3 INTERACTION 4.4 TRANSFORMATION 4.5 VIEWING 4.6 SOURCE CODE 5. SNAPSHOTS 17 6. TESTING 18 CONCLUSIONS FUTURE ENHANCEMENT REFERENCES
  • 6. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 1 Chapter 1 INTRODUCTION The dominant characteristics of this new computer and communication technologies have become dominant forces in our life. Activities as wide ranging as filmmaking, publishing, banking and education continue to undergo revolutionary changes as these technologies alter the ways in which we conduct our daily activities. The combination of computers , networks, and the complex visual system, through the computer graphics has led to new way of displaying information, seeing virtual worlds and communicating with people and machines. Computer graphics is concerned with all aspects of producing pictures or images using a computer. The field has begun humbly almost 50 years ago, with a display of few lines on a cathode ray tube, now we can create images by computer that are indistinguishable from photographs of real objects. We routinely train pilots with simulated airplanes, generating graphical displays of virtual environment of real time. Feature length movies made entirely by computer have been successful, both critically and financially. Massive multiplayer games can involve tens of thousands of concurrent participants. 1.1 GLUT: It is complete API written by mark kilogram, which lets us create windows and handle the messages. It exists for several platforms that a program, which uses GLUT, can be compiled on many platforms without any changes in the code. ADDITONAL LIBRARIES: There are two libraries functions that we have learnt in OpenGL. 1 .glu :It is a set of utility functions, they are easy way of doing things that is tedious with raw OpenGL. 2. glx :It allows you to open up X window and link it up with OpenGL so that it will draw to that window.
  • 7. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 2 1.2 HOW OpenGL WORKS? To be hardware independent OpenGL provides its own data types, they all begin with “GL”. Eg: GLfloat, Glint. There are also many symbolic constants that all begin with ”GL”. Eg: GL_POINTS, GL_LINES. Finally commands have prefix ”gl”. Eg: glVertex3f (f, i, d). There are utility library called as “GLU”. Here the prefixes are “GLU_”, ”glu”. GLUT commands begin with “glut” it is same for every library. OpenGL is a widely accepted standard for developing graphics applications. Fortunately, OpenGL is easy to learn and it possesses most of the characteristics of other graphics systems. Graphics API’s such as OpenGL, developed as a way to provide application programmers with the access to hardware features that were being provided by the latest graphics hardware. Application of Computer Graphics: The development of computer graphics has been driven both by needs of the user community and by advancement in technology. The applications of computer graphics of computer graphics are many and varied, we can divide them into four categories : 1. Display of information 2. Design 3. Simulation and Animation 4. User interface 1. Display of Information: Medical imaging possess interesting and important data analysis problem. Modern imaging technologies such as computed tomography (CT), magnetic resonance imaging(MRI), ultrasound, and position emission tomography(PET), generate 3D data that must be subjected to algorithmic manipulation to provide useful information. The field of scientific visualization provides graphical tools that help the researchers interpret the fast quantity of data that generate.
  • 8. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 3 2. Design: Professions such as engineering and architecture are concerned with design. Starting with a set of specifications, engineers and architects seek a cost effective and esthetical solution that satisfies the specifications. Design is an interactive process. Design problem are either over determined such that they possess no solution that satisfies all criteria, much less an optimal solution, or undetermined, such that they have multiple solutions that satisfies the design criteria. 3. Simulation and Animation: Graphics system evolved to be capable of generating sophisticated images in real time, engineers and researchers began to use them as simulators. One of the most important use has been in training of pilots. The use of special PLSI chips has led to a generation of arcade, games as sophisticated as flight simulators. The simulators can be used for designing the robot, planning its path, and simulating its behaviour in complex environment. The success of flight simulators led to the use of computer graphics for animation in TV, motion pictures and advertising industries. Entire animated movies can now be made by computers at a cost less than that of movies made with traditional ways. 4.User interface: Our interaction with computers has become dominated by visual paradigm that includes icons, menus and pointing devices such as mouse. From users perspectives, winding system such as X and window system, Microsoft windows. 1.3 OPENGL: • Graphics rendering API. • High Quality colour images composed of geometric primitives • Operating system independent
  • 9. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 4 • OpenGL is an application programmer’s interface (API) that allows programmers to write programs that access graphics hardware. OpenGL provide a set of commands to render a two dimensional scene. That means you provide data in OpenGL usable form and OpenGL will show you this data in scene (render it).it is developed by many companies and it is free for use. You can develop OpenGL applications without licensing. OpenGL based on the state variables, there are many values for example, the colour, you can specify a colour once and draw several polygons, lines and whatever you want. Then there are no classes like in directX. However it is logically structured. Before we come to the commands themselves, here are another thing. To be hardware independent, OpenGL provides its own data types . They all begin with “GL”. For ex: GLfloat, GLint and so on. There are also many symbolic constants; they all begin with “GL” for ex: GL_POINTS, GL_LINES. Finally the commands have the prefix “gl”. There is utility library called GLU, here the prefixes are “GLU” & “glu”. It is same for every library. You want to know which library coexist with the one called before. There are libraries for every system. Windows as the wgl*functions, UNIX system glx* and so on. It is very important thing to know, that there are two important matrices, which affect the transformation from 3D world to 2D screen. The projection matrix and the model view matrix. The projection matrix contains information, how a vertex can be mapped tom the screen. This contains, whether the projection shall be isometric or a form of perspective, how wide the field of view is and so on. Into the other matrix you put information, how the objects are moved, where the viewer is and so on.
  • 10. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 5 The OpenGL pipeline: Fig1.3.1: the OpenGL rendering pipeline Commands may be either be accumulated in display lists are processed immediately through pipeline architecture. Display lists allow for greater optimization and command reuse, but not all commands can be put in display lists. The first stage is evaluator. This stage effectively takes any polynomial evaluator commands and evaluates them into their corresponding vertex and attributes commands The second stage is per-vertex operations, including transformations, lighting, primitive assembly, clipping, projection, and viewport mapping. The third stage is rasterization. This stage produces fragments, which are series of frame buffer address and values from the viewport mapped primitives as well as bitmaps and pixel rectangles. The fourth stage is the per-fragment operations. Before fragments go to the frame buffer, they may subjected to a series of conditional tests and modifications, such as blending or Z- buffering.
  • 11. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 6 1.4 PROJECT INTRODUCTION Introduction to Ping Pong Ball Game using OpenGL The Ping Pong Ball Game implemented using OpenGL is a simple yet entertaining 2D arcade game. It recreates the popular table tennis sport.In this game, the players aim to score points by successfully hitting the ball past their opponent's paddle. The game utilizes OpenGL, a powerful graphics library, to render the game elements and create an immersive visual experienceThe game environment consists of a rectangular playfield representing the ping pong table. Each player controls a paddle, which is a rectangular shape on their side of the table. The ball, represented by a small circular shape, moves dynamically across the playfield. The game employs OpenGL's capabilities to handle graphics rendering, animation, and collision detection. It ensures smooth movement of the ball and paddles, allowing for realistic gameplay. The collision detection mechanism determines when the ball contacts the paddles, walls, or other game objects, enabling appropriate reactions such as bouncing the ball off the paddles.Additionally, the game keeps track of the players' scores, incrementing them whenever a player fails to return the ball successfully. The game typically ends when one player reaches a predetermined score or after a fixed duration of play. Overall, the Ping Pong Ball Game project demonstrates the power of OpenGL in creating an engaging and interactive gaming experience. By simulating the dynamics of table tennis, it provides an enjoyable challenge for players. Through the combination of keyboard controls, smooth graphics, and accurate collision detection, this project showcases the potential of OpenGL in developing 2D games.
  • 12. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 7 Chapter 2 SYSTEM REQUIREMENTS 2.1 Software Requirements: • An MS_DOS based operating system like windows XP • Avisual C/C++ compiler is required for compiling the source code to make a executable file which can be directly executed • The built in graphics and dynamic link libraries like glut and glut32, and header file like glut.h to create 2D &3D layout. 2.2 Hardware Requirements: • Processor : intel 486/Pentium processor and above • Processor speed : 500MHz or above • RAM : 64 MB or above • Storage space : 50 MB or above • Monitor Resolution : colour monitor with minimum resolution of 640*480
  • 13. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 8 Chapter 3 PROJECT DESIGN 3.1 PURPOSE Demonstration of simulation of 2D Ping Pong Ball Game . 3.2 DESCRIPTION The player can control their respective paddles using keyboard inputs. The specific keys use for control can vary, but typically they are assigned to the left and right direction using 'B' and 'N' keys. By pressing the designated keys, the player can move their paddles left and right, attempting to intercept the ball. The game environment consists of a rectangular playfield representing the ping pong table. Player controls a paddle, which is a rectangular shape on their side of the table. The ball, represented by a small circular shape, moves dynamically across the playfield. Additionally, the game keeps track of the player score, incrementing them whenever a player fails to return the ball successfully. The game typically ends when one player reaches a predetermined score or after a fixed duration of play. But there is a condition to this game ,if the player moves the paddle to the extreme left the player is disqualified.
  • 14. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 9 2.3 FLOW CHART if paddle = extreme left Fig2.3.1: Flowchart for Simulation of 3D Windmill START MAIN INITIALIZE CALLBACK FUNCTIONS STOP MAIN SCREEN DISPLAYED Keyboard ‘N’ for right ‘B’ for left EVENTS ‘Q’ for exit
  • 15. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 10 Chapter 4 IMPLEMENTATION This program has been developed and implemented using OpenGL interface. In corporate this facility includes glut.h header files. • Void glBegin(glEnum mode) Initiates a new primitive of mode and starts the collection of vertices. Values of mode include GL_POITS, GL_LINES and GL_POLYGON. • Void glEnd() Terminates a list of vertices. 4.1 Attributes ➢ Void glColor3[b I f d ub us ui](TYPE r, TYPE g, TYPE b) Sets the present RGB colors. Valid types are byte(b),int (i), float (f), double (d), unsigned byte(ub), unsigned short(us) and unsigned int (ui). 1. Void glClearColor(GLclampfg,Glclampfg,Glclampfb, Glclampfa) Sets the present RGBA clear color used when clearing the color buffer. Variable of Glclampf are floating point numbers between 0.0 and1.0. 2. Void glPointSize(Glfloat size) Sets the point size attribute in pixels. 4.2 Working with the window system ➢ Void glFlush() Forces any buffered openGL commands to execute. ➢ Void glutInit(int argc, char **argv) Initializes GLUT. The arguments from main are passed in and can be used by the application.
  • 16. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 11 ➢ Void glutCreateWindow(char*title) Creates a window on the display. The string title can be used by the window. The return value provides reference to the windows that can be used when there are multiple windows. ➢ void glutInitDisplayMode(unsigned int mode) Requests a display with the properties in mode. The value of mode is determined by the logical OR of options including the colormodel(GLUT_RGB, GLUT_INDEX) and buffering (GLUT_SINGLE,GLUT_DOUBLE). ➢ void glutInitWindowSize(intwidth,int height) Specifies the initial height and width of the window in pixels. ➢ void glutInitWindowPosition(intx,int y) Specifies the initial position of top-left corner of the window in pixels. ➢ void glViewport(intx,inty,Glsizei height) Specifies a width x height viewport in pixels whose lower left corner is at(x,y) Measured from origin of the window. ➢ void glutMainLoop() Causes the program to enter an event processing loop. It should be the lat statement in main. ➢ Void glutDisplayFunc(void(*func)(void)) Requests that the display callback be executed after the current callback returns. ➢ void glutSwapBuffers() Swaps the front and back buffers. 4.3 Interaction ➢ Void glutKeyboardFunc(void *f(char key,intwidth,int height) Register the keyboard callbackfunc f. The callback function returns the ASCII ode of the key pressed and the position of the mouse.
  • 17. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 12 ➢ Void glutIdleFunc(void (*f)(void)) Registers the display callback function f that is executed whenever there are no other events to be handled. 4.4 Transformation ➢ void glMatrixmode(Glenum mode) Specifies which matrix will be affected by subsequent transactions. Mode can be GL_MODEL_VIEW,GL_PROJECTION or GL_TEXTURES. ➢ Void glLoadIdentity() Sets the current transformation matrix to an identity matrix. ➢ void glTranslate[fd](TYPE x, TYPE y, TYPE z) Alters the current matrix by a displacement of(x,y,z). TYPE is of either Glfloat or Gldouble. ➢ Void glScale[fd]](TYPE x, TYPE y, TYPE z) Alters the current matrix by scaling of(sx,sy,sz). TYPE is either Glfloat or Gldouble. 4.5 Viewing ➢ Void glOrtho2D(Gldoubleleft,Gldoubleright,Gldoublebottom,Gldouble top) Defines a two dimentional viewing rectangle in the planes z=0.
  • 18. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 13 4.7 SOURCE CODE // C program to illustrate OpenGL game #include <stdio.h> #include <GL/glut.h> #include <math.h> #include <unistd.h> //for WINDOWS run use below library //#include<windows.h> #define pi 3.142857 // Global Declaration // c and d tracks the number of time 'b' and 'n' pressed respectively // left and right indicates leftmost and rightmost index of movable rectangle int c = 0, d = 0, left = 0, right = 0; int m = 0, j = 1, flag1 = 0, l = 1, flag2 = 0, n = 0, score = 0, count = 1; // Initialization function void myInit(void) { sleep(1); // Reset background color with white (since all three argument is 1.0) glClearColor(1.0, 0.0, 0.0, 0.0); // Set picture color to red (in RGB model) // as only argument corresponding to R (Red) is 1.0 and rest are 0.0 glColor3f(1.0f, 0.0f, 0.0f); // Set width of point to one unit glPointSize(1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Set window size in X- and Y- direction gluOrtho2D(-620.0, 620.0, -340.0, 340.0); } // keyboard function : it gets active when button pressed void keyboard(unsigned char key, int x, int y) { left = -200 + 200 * (d - c); right = 200 + 200 * (d - c); // if leftmost index of window is hit // then rectangle will not move to left on further pressing of b // only it will move to right on pressing n if (left == -600) {
  • 19. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 14 // '110' -> Ascii value of 'n' // so d is incremented when n is pressed if (key == 100) d++; } // if rightmost index of window is hit // then rectangle will not move to right on further pressing of n // only it will move to left on pressing b else if (right == 600) { // '98' -> Ascii value of 'b' // so c is incremented when b is pressed if (key == 98) c++; } // when rectangle is in middle, then it will move into both // direction depending upon pressed key else { if (key == 98) c++; if (key == 110) d++; } glutPostRedisplay(); } void myDisplay(void) { // x and y keeps point on circumference of circle int x, y, k; // outer 'for loop' is to for making motion in ball for (k = 0; k <= 400; k += 5) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_LINE_STRIP); // i keeps track of angle float i = 0; // change in m denotes motion in vertical direction and // change in n denotes motion in horizontal direction m = m + 6; n = n + 4; // drawing of circle centre at (0, 12) iterated up to 2*pi, i.e., 360 degree while (i <= 2 * pi) { y = 12 + 20 * cos(i); x = 20 * sin(i); i = i + 0.1; // flag1 is 0 to show motion in upward direction and is 1 for downward direction if (m == 288 && flag1 == 0)
  • 20. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 15 { j = -1; m = -288; flag1 = 1; score++; } if (m == 288 && flag1 == 1) { j = 1; m = -288; flag1 = 0; } // flag2 is 0 to show motion in rightward direction and is 1 for leftward direction if (n == 580 && flag2 == 0) { l = -1; n = -580; flag2 = 1; } if (n == 580 && flag2 == 1) { l = 1; n = -580; flag2 = 0; } // equation for desired motion of ball glVertex2i((x - l * n), (y - j * m)); } glEnd(); // these four points draws outer rectangle which determines window glBegin(GL_LINE_LOOP); glVertex2i(-600, -320); glVertex2i(-600, 320); glVertex2i(600, 320); glVertex2i(600, -320); glEnd(); // these four points draws smaller rectangle which is for catching ball glBegin(GL_LINE_LOOP); left = -200 + 200 * (d - c); right = 200 + 200 * (d - c); glVertex2i(left, -315); glVertex2i(left, -295); glVertex2i(right, -295); glVertex2i(right, -315); glEnd(); // following condition checks if falling ball is catched on rectangle or not if ((j * m) == 276)
  • 21. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 16 { if ((left > ((-1 * l * n) + 20)) || (right < (-1 * l * n) - 20)) { printf("Game Over !!!nYour Score is :t%dn", score); exit(0); } } glutSwapBuffers(); } } // Driver Program int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); // Declares window size glutInitWindowSize(1100, 600); // Declares window position which is (0, 0) // means lower left corner will indicate position (0, 0) glutInitWindowPosition(50, 50); // Name to window glutCreateWindow("Game"); // keyboard function glutKeyboardFunc(keyboard); // Call to myInit() myInit(); glutDisplayFunc(myDisplay); glutMainLoop(); }
  • 22. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 17 Chapter 5 SNAPSHOTS
  • 23. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 18
  • 24. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 19 Chapter 6 TESTING 6.1 TESTING Software testing is a critical element of the ultimate review of specification design and coding. Testing of software leads to the uncovering of errors in the software functional and performance requirements are met. Testing also provides a good indication of software reliability and software quality as a whole. The result of different phases of testing are evaluated and then compared with the expected results. If the errors are uncovered they are debugged and corrected. A strategy approach to software testing has the generic characteristics: • Different testing techniques are appropriate at different points of time. • Testing and debugging are different activities, but debugging must be accommodated in the testing strategy. Following three approaches of debugging were used: o Debugging by Induction o Debugging by Deduction o Backtracking 6.2 TEST PLANS In this test plan all major activities are described below: • Unit testing. • Integration testing. • Validation testing. • System testing.
  • 25. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 20 Table 5.3: Test case for keyboard SL.no Test case descrip- tion Expected result Actual result Remarks 1. Press Enter to start game Will start the game Will start the game PASS 2. Press B for left Move the pebble left Move the pebble left PASS 3. Press N for right Move the pebble right Move the pebble right PASS 4. Press Q for exit Exit the game Exit the game PASS
  • 26. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 21 CONCLUSIONS In conclusion, the development of a single-player 2D Ping Pong Ball Game using OpenGL has resulted in a captivating and enjoyable gaming experience. The integration of OpenGL's graphics capabilities has allowed for the creation of a visually appealing game environment. By controlling a paddle and interacting with the ball, players can relish the excitement and challenges of a classic ping pong game in a virtual setting. The game's implementation of responsive controls, smooth animations, and accurate collision detection contributes to a realistic and immersive gameplay experience. The utilization of 2D elements such as the paddles, ball, and playfield brings the game to life and creates an engaging atmosphere. Moreover, the project highlights the versatility of OpenGL as a graphics library and its compatibility with various programming languages. The seamless integration of OpenGL with the game's logic allows for efficient rendering and optimized performance. In summary, the single-player 2D Ping Pong Ball Game developed using OpenGL delivers an immersive and entertaining gaming experience.
  • 27. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 22 FUTURE ENHANCEMENT This project has been designed using C, which works on the windows platform. The project can be designed using other languages and better graphical interfaces. The following features could have been incorporated. ✓ Enabling multiplayer functionality. ✓ In window interaction. ✓ Enabling score board in GUI in window.
  • 28. Ping Pong Game DEPT OF CSE, SVCE 2022-2023 Page 23 REFERENCES BIBLIOGRAPHY [1] Edward Angel’s Interactive Computer Graphics Pearson Education 5th Edition [2] Interactive computer Graphics - A top down approach using open GL by Edward Angel [3] Jackie L.Neider,Mark Warhol, Tom R.Davis,"OpenGL Red Book", Second Revised Edition,2005. [4] Donald D Hearn and M.PaulineBaker,"Computer Graphics with OpenGL",3rd Edition. WEBSITES [5] www.OpenGLRedbook.com [6] www.OpenGLsimpleexamples.com