Vishveshwarya Technological University BELAGAVI - 590018.: A Mini Project Report On
Vishveshwarya Technological University BELAGAVI - 590018.: A Mini Project Report On
Vishveshwarya Technological University BELAGAVI - 590018.: A Mini Project Report On
BELAGAVI – 590018.
K.L.E. Society’s
“WRAP-AROUND MINESWEEPER”
For
Submitted in partial fulfillment for the VI semester CGV Laboratory with Mini Project
[18CSL67]
Submitted By,
Mr. Aditya Ghorpade
USN: 2KD18CS003
2021 – 2022
Under the Guidance of,
Prof. Madhurani B S
Dept Of Computer Science and Engineering
K.L.E. Society’s
KLE COLLEGE OF ENGINEERING & TECHNOLOGY,
CHIKODI - 591201.
.
2021-2022
1)
2)
ACKNOWLEDGEMENT
The success and final outcome of this mini project required a lot of guidance and assistance
from many people and we are extremely fortunate to have got this all along the completion of our
project work. Whatever we have done is only due to such guidance and the assistance.
We owe our profound gratitude to our mini project guide Prof. Madhurani B Shiddibhavi,
who took keen interest in our project work and guided us all along, till the completion of our project
work by providing all the necessary information and valuable suggestion for developing a good
system.
With deep sense of gratitude, we also acknowledge the encouragement of the Head of the
Department Prof. Ashwini Gavali, for her continuous support and permitting to make use of the
facilities available in the department.
We express our sincere gratitude to Dr. Prasad B. Rampure, Principal, KLE College of
Engineering & Technology, Chikodi for his support and encouragement in this regard.
We also thankful and fortunate enough to get constant encouragement, support and guidance
from entire teaching and non-teaching staff of Department of Computer Science and Engineering
who helped us in successful completion of our mini project work.
Last but not least, we are thankful to our Parents, family members and all our friends for their
support and help, extended during this project.
2.1 OpenGL 3
2.2Problem Section Statement 5
2.3 Existing Statement 5
2.4 Proposed System 5
2.5 Objectives of The Project 6
3. System Requirement 7
Specification
3.1 User Requirements 7
3.2 Hardware Requirements 7
3.3 Software Requirements 7
4. Design and Implementation 8-10
4.1 Design 8
4.2 Header Files 9
4.3 Simple Geometry 9
4.4 Interaction 10
4.5 Transformation 10
4.6 Viewing 10
5. Source Code 11-19
Conclusion 22
References 23
LIST OF FIGURES
CHAPTER 1
INTRODUCTION
1.1 Overview
The term “Computer Graphics” includes almost everything on computers that is not text
or sound. Today nearly all computers use some graphics and users expect to control their
computer through icons and pictures rather than just by typing. Computer graphics is the field
of visual computing, where one utilizes computers both to generate visual images
synthetically and to integrate or alter visual and spatial information sampled from the real
world. The term computer graphics has several meanings:
The representation and manipulation of pictorial data by a computer.
The various technologies used to create and manipulate such pictorial data.
The sub-field of computer science which studies for digitally synthesizing and
manipulating visual content.
This field can be divided into several areas: real-time 3D rendering (often used in video
games), video capture and video creation rendering, special effects editing (often used for
movies and television), image editing and modelling (often used for engineering and medical
purposes).
1.2 History
Computer graphics started with pen plotter model. We had Cathode Ray Tube Display
showing the graphics. Each line drawn was a result of intense calculation which was a huge
overhead a few years back.
The phrase “Computer Graphics” was coined in 1960 by William fetter, a graphic
designer for Boeing. The field of computer graphics developed with the emergence of
computer graphics hardware. Early projects like the whirlwind and SAGE Projects introduced
the CRT as a viable display and interaction interface and introduced the light pen as an input
device.
In 1959, the TX-2 computer was developed at MIT’s Lincoln Laboratory. The TX-2
integrated a number of new man-machine interfaces. A light pen could be used to draw
sketches on the computer using Ivan Sutherland’s revolutionary Sketchpad software. Using a
light pen, Sketchpad allowed one to draw simple shapes on computer screen, save them and
even recall them later.
Many of the most important early breakthroughs in computer graphics research occurred
at the University of Utah in the 1970s. A student by the name of Edwin Catmull saw
computers as the natural progression of animation and they wanted to be part of the
evolution. He created an animation of his hand opening and closing. The first major advance
in 3D computer graphics was created at UU by these early pioneers, the hidden surface
algorithm.
In the 1980s, artist and graphics designer began to see the personal computer, particularly
the Commodore Amiga and Macintosh, as a serious design tool, one that could save time and
draw more accurately than other methods. In the late 1980s, SGI computers were used to
create some of the first fully computer-generated short films at Pixar.
Computational biology
Computational physics
Computer-aided design
Computer simulation
Digital art
Graphic design
Info graphics
Information visualization
Scientific visualization
CHAPTER 2
LITERATURE SURVEY
OpenGL was developed by Silicon Graphics Inc. (SGI) in 1992and is widely used in
CAD, virtual reality, scientific visualization, information visualization, and flight simulation.
It is also used in video games, where it competes with Direct3D on Microsoft Windows
platforms.
The interface between the application program and the graphics system can be specified
through that set of function that resides in graphics library. The specification is called the
APPLICATION PROGRAM INTERFACE (API). The application program sees only the
API and is thus shielded from the details both the hardware and software implementation of
graphics library. The software driver is responsible for interpreting the output of an API and
converting these data to a form that is understood by the particular hardware.
Most of our applications will be designed to access openGL directly through functions
in three libraries. Function in the main GL library have name that begin with the letter gl and
stored in the library. The second is the openGL utility Library (GLU). This library uses only
GL function but contains codes for creating common object and viewing. Rather than
using a different library for each system we used available library called openGL utility
toolkit (GLUT). It used as #include <glut.h>
A graphics editor is a computer program that allows users to compose and edit pictures
interactively on the computer screen and save them in one of many popular “bitmap” or
“raster” a format such as TIFF, JPEG, PNG and GIF.
Computer Graphics is concerned with all aspects of producing pictures or images using
a computer. A particular graphics software system called OpenGL, which has become a
widely accepted standard for developing graphics applications.
The applications of computer graphics in some of the major areas are as follows
1. Display of information.
2. Design.
3. Simulation and Animation.
4. User interfaces.
The geometric objects are the building blocks of any individual. Thereby developing,
manipulating, applying any transformation, rotation, scaling on them is the major task of any
image development.
Thereby we have put our tiny effort to develop 2D objects and perform different
operations on them by using OpenGL utilities.
CHAPTER 3
SYSTEM REQUIREMENT SPECIFICATION
3.1 User Requirements
Easy to understand and should be simple.
The built-in functions should be utilized to the maximum extent.
OpenGL library facilities should be used.
CHAPTER 4
DESIGN AND IMPLEMENTATION
To design the ‘Wrap-around Minesweeper Game’ using the glut library, we need to
understand various concepts, components and utility functions that are essential to
implement/integrate the required visual (and audio) effects. Hence by using the following
functions we design our project.
4.1 Design
The OpenGL specification describes an abstract API for drawing 2D and 3D graphics.
Although it is possible for the API to be implemented entirely in software, it is designed to be
implemented mostly or entirely in hardware.[4]
The API is defined as a number of functions which may be called by the client program,
alongside a number of named integer constants (for example, the constant
GL_TEXTURE_2D, which corresponds to the decimal number 3553). Although the function
definitions are superficially similar to those of the C programming language, they are
language-independent. As such, OpenGL has many language bindings, some of the most
noteworthy being the JavaScript binding WebGL (API, based on OpenGL ES 2.0, for 3D
rendering from within a web browser); the C bindings WGL, GLX and CGL;
#include <math.h>
math.h is a header file in the standard library of the C programming language designed
for basic mathematical operation.
glVertex2f(coordinates): This function defines the vertices of 2D figure with float as data
type.
GlutInit(int argc, char *argv): Initialize GLUT. The arguments from main are passed in
and can be used by the application.
glutCreateWindow(char*title): Create a Window on the display, the string title can be used
to label the window. The return value provides a reference to the window that can be used
when there are multiple windows.
glutDisplayMode(unsigned int mode): Request a display with the properties in mode the
value of mode is determined by the logical or of options including the color model
(GLUT_RGB,GLUT_INDEX) and buffering (GLUT_SINGLE,GLUT_DOUBLE).
glutInitWindowPosition(int x, int y): Specifies the initial position of top-left corner of the
window in pixels.
glutPostRedisplay(): Requests that the display callback be executed after the current
callback returns.
glutMainLoop(): Causes the program to enter an event processing loop. It should be the last
statement in main.
4.4 Interaction
glutKeyboardfunc(void(*func)(unsigned char key,int x,int y)): Sets the keyboard callback
for the current window. When a user types into the window, each key press generating an
ASCII character will generate a keyboard callback.
glutMousefunc(void(*func)(int button, int state, int x,int y)): Sets the Mouse callback for
the current window. When user clicks on something on the window, each click generates a
state and a button value that is passed to this callback.
4.5 Transformations
glMatrixMode(GL_PROJECTION): Here the mode will be projection mode, specifies
subsequent transformation matrix to an identity matrix.
4.6 Viewing.
glOrtho (left,right,bottom,top,near,far): It defines a 3 dimensional Orthographic view
CHAPTER 5
SOURCE CODE
The entire project is divided into 3 files, main.cpp, gameMechanics.cpp and drawer.cpp.
All these files must be linked together while compiling.
drawer.cpp takes care of all the OpenGL based drawing functions implementations
gameMechanics.cpp takes care of the rules that the game must follow during runtime.
1. drawer.cpp:
#include "drawer.hpp"
#include <GL/gl.h>
#include <GL/glut.h>
#include <math.h>
#include <iostream>
#include <unistd.h>
int boomOrNumberFlag = 1;
void Drawer::drawWelcomeScreen(int h, int w) //Draws Welcome Screen
{ renderBox(h, w, 3);
glColor3f(0,0,0);
glLineWidth(5.0);
glColor3f(1.0f, 0.0f, 0.0f);
drawStrokeText("Wrap-Around", (w/3)*CELL_WIDTH + 15, (h/3)*CELL_HEIGHT + 65, 0, 0.5, 0.35f);
drawStrokeText("Minesweeper", (w/3)*CELL_WIDTH + 15, (h/3)*CELL_HEIGHT + 115, 0, 0.5, 0.35f);
glColor3f(0.0f, 0.0f, 0.0f);
drawStrokeText("By", (w/3)*CELL_WIDTH + 15, (h/3)*CELL_HEIGHT + 165, 0, 1.0, 0.25f);
drawStrokeText("Akhil S", (w/3)*CELL_WIDTH + 15, (h/3)*CELL_HEIGHT + 205, 0, 0.8, 0.25f);
drawStrokeText("Abhijith C", (w/3)*CELL_WIDTH + 15, (h/3)*CELL_HEIGHT + 245, 0, 0.8, 0.25f);
glLineWidth(1.0);
glutSwapBuffers();
}
void Drawer::drawMine(int x, int y) //Draw a Black Pentagon for a mine
{
drawOpenedField(x, y); //Place a mine on the opened field
glColor3f(0.0f, 0.0f, 0.0f);
glBegin(GL_POLYGON);
for (int i = 0; i < 5; ++i)
{
glVertex2f(x * CELL_WIDTH + CELL_WIDTH / 2 + 5.0f * cos(2 *3.1415926 * i / 5), y * CELL_HEIGHT
+ CELL_HEIGHT / 2 + 5.0f * sin(2 * 3.1415926 * i / 5));
}
glEnd();}
glEnd();
}
void Drawer::drawOpenedField(int x, int y, int neighbourMinesCount)
{
drawOpenedField(x, y);
if (neighbourMinesCount > 0)
{
switch (neighbourMinesCount)
{
case 1:
glColor3f(0.0f, 1.0f, 0.0f); //Green
break;
case 2:
glColor3f(0.0f, 0.0f, 1.0f); //Blue
break;
case 3:
glColor3f(1.0f, 0.0f, 0.0f); //Red
break;
case 4:
glColor3f(0.0f, 0.7f, 0.0f); //Celebi Green
break;
case 5:
glColor3f(0.5f, 0.4f, 0.0f); //Dragonite Orange
break;
case 6:
glColor3f(0.0f, 0.8f, 0.5f); //Grovyle Green
break;
case 7:
glColor3f(0.1f, 0.1f, 0.1f); //Onyx Grey
break;
case 8:
glColor3f(0.3f, 0.3f, 0.3f); //Geodude Grey
break;
}
glRasterPos2f(x * CELL_WIDTH + (15 - 9) / 2 + 1, (y + 1) * CELL_HEIGHT-1);
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, '0' +neighbourMinesCount);
}
}
void Drawer::drawOpenedField(int x, int y)
{
glColor3f(0.6f, 0.6f, 0.6f);
glBegin(GL_QUADS);
2. gameMechanics.cpp :
#include "gameMechanics.hpp"
#include "drawer.hpp"
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <thread>
#include <unistd.h>
int
initial
= 0;
Draw
er d;
int retFlag = 0,
anotherFlag = 0;int X,
Y;
int
winFlag
= 0;void
boom()
{
system("play boom.wav 2> /dev/null");
}
void win()
{
system("play ToToDo.wav 2> /dev/null");
}
Game::Game()
{ gameOver =
false; srand (
time(NULL) );
for (int y = 0; y < HEIGHT;
++y) for (int x = 0; x <
WIDTH; ++x)
{
field_[x][y].state =
CLOSED;
field_[x][y].hasMine
= false;
}
for (int i = 0; i < 30; ++i)
{
DEPT OF CSE, KLECET 2021-2022 Page 15
i
n
t
WRAP-AROUND MINESWEEPER
{
switch (field_[x][y].state)
{
case CLOSED:
d.drawClosedField(x, y); //Draw a closed field
break;
case OPENED:
if (!field_[x][y].hasMine)
{
int neighbourMinesCount = 0;
for (int yy = y - 1; yy <= y + 1; ++yy){
for (int xx = x - 1; xx <= x + 1; ++xx)
{
if ((xx == x && yy == y) || xx < 0 || xx >= WIDTH
|| yy < 0 || yy >= HEIGHT)
continue;
if (field_[xx][yy].hasMine)
++neighbourMinesCount;
}
}
d.drawOpenedField(x, y, neighbourMinesCount);
if(anotherFlag)
{
int depth = 2;
for(int k = 1; k <= depth;k++){
if(X > 0 && !gridSweeper(X-k, Y)) break;
if(Y > 0 && !gridSweeper(X, Y-k)) break;
if(X < WIDTH && !gridSweeper(X+k, Y))
break;
if(Y < HEIGHT && !gridSweeper(X, Y+k)
break;
if(X > 0 && Y > 0 && !gridSweeper(X-k, Y-k))
break;
if(X < WIDTH && Y < HEIGHT &&!
gridSweeper(X+k, Y+k)) break;
}
anotherFlag = 0;
}
}
else
{
if(!boomFlag){
}
sleep(1);
if(!gameWonFlag)
{
d.gameOver((int)HEIGHT, (int)WIDTH);
}
else
{
d.gameWon((int)HEIGHT, (int)WIDTH);
}
}
}
void Game::markFlag(int x, int y)
{
switch (field_[x][y].state)
{
case OPENED:
break;
case CLOSED:
field_[x][y].state = FLAG;
break;
case FLAG:
field_[x][y].state = CLOSED;
break;
}
}
void Game::open(int x, int y)
{
if(!((field_[x][y].state == FLAG)||(field_[x][y].state == OPENED)))
{
field_[x][y].state = OPENED;
anotherFlag = 1;
X = x;
Y = y;
}
}
3. main.cpp :
#include "drawer.hpp"
#include "gameMechanics.hpp"
#include <GL/glut.h>
#include <unistd.h>
Game game;
void display()
{ glClear(GL_COLOR_BUFFER_BIT);
game.draw();
glutSwapBuffers(); }
void keyPressed (unsigned char key, int x, int y) {
if (key == 'q') {
exit(0); }
else if(key == 'r'){ game = Game(); }}
void reshape(int w, int h)
{ glutReshapeWindow(Game::WIDTH * Drawer::CELL_WIDTH, Game::HEIGHT * Drawer::CELL_HEIGHT); }
void mouse(int button, int state, int x, int y) // Mouse functions here..
{ if (state == GLUT_UP)
{ switch (button)
{ case GLUT_LEFT_BUTTON: //Open that tile
game.open(x / Drawer::CELL_WIDTH, y / Drawer::CELL_HEIGHT);
break;
case GLUT_RIGHT_BUTTON: //Place a Flag here
game.markFlag(x/Drawer::CELL_WIDTH,y/ Drawer::CELL_HEIGHT);
break;
} glutPostRedisplay(); } }
int main(int argc, char **argv)
{ glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(Game::WIDTH * Drawer::CELL_WIDTH, Game::HEIGHT *Drawer::CELL_HEIGHT);
glutInitWindowPosition(100, 120);
glutCreateWindow("Wrap-Around MineSweeper");
glClearColor(0, 0, 0, 1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Game::WIDTH * Drawer::CELL_WIDTH, Game::HEIGHT * Drawer::CELL_HEIGHT, 0, -1.0, 1.0);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyPressed);
glutMouseFunc(mouse); //Call the mouse function here
glutMainLoop(); }
CHAPTER 6
SNAPSHOTS
CONCLUSION
An attempt has been made to develop an OpenGL graphics package, which meets
necessary requirements of the users successfully. It enables us to learn about the basic
concept in OPENGL graphics and graphics and know standard library graphics
function and to explore some other function. OpenGL graphics is a huge library which
consists of numerous functions. The various shapes at lower level or to simulate any
real thing animation etc. at high level. This project has given us an insight into the use
of Computer graphics. As we had to use many built-in and user defined functions, we
have managed to get a certain degree of familiarity with these functions and have now
understood the power of these functions. We were able to comprehend the true nature
of the most powerful tool graphics in OpenGL and have understood the reason why
graphics is so powerfulfor programmers. We can now converse with the certain degree
of confidence about graphics in openGL. Finally, we have implemented this mini
projection "Wrap-Around Minesweeper Game" using openGL package. We would
like to end by saying that doing this graphics project has been a memorable experience
in which we have learned a lot, although there is a scope for further improvement. We
got to know a lotof different applications of OPENGL while doing this project.
REFERENCES
Books:
Reference Websites:
[4] freeglut.sourceforge.net/docs/api.php
[5] www.opengl.com
[6] www.learnopengl.com
[7] www.tutorialspoint.com
[8] https://en.wikipedia.org/wiki/OpenGL