Subbisush
Subbisush
Subbisush
CHAPTER 1
INTRODUCTION
The aim of this project is to develop a The Epilogue of Education. A child can choose to
doctor,anengineer,apilot,ascientist,anartist,anentrepreneur,apolitician,apoliceman,agovernment
official ,a marketer ,a cricketer ,a football player ,a hockey player ,a professional bowler ,a
lawyer ,a designer ,a developer ,a photographer ,a dancer ,a singer .He /She could be a super hero
if they wished to be. The opportunities are endless.. The interface should be user friendly and
should use keyboard interface for the interaction with the user. The main goal is a story that
defines the problems of education in our current society, and how we are far off from an actual
smart world.
The term computer graphics includes almost everything on computers that is not text or sound. Today
almost every computer can do some graphics, and people have even come to expect to control
their computer through icons and pictures rather than just by typing .Computer graphics are
created using computers and the representation of image data by a computer specifically with
help from specialized graphic hardware and software. The interaction and understanding of
computers and interpretation of data has been made easier because of computer graphics. A
computer graphic development has had a significant impact on many types of media and has
revolutionized animation, movies and the video game industry. Typically, the term computer
graphics refers to several different things:
The representation and manipulation of image data by a computer
The various technologies used to create and manipulate images
The sub-field of computer science which studies methods for digitally synthesizing and
manipulating visual content.
Computer generated imagery can be categorized into several different types: two dimensional
(2D), three dimensional (3D), and animated graphics. As technology has improved, 3D computer
graphics have become more common, but 2D computer graphics are still widely used. Computer
graphics has emerged as a sub-field of computer science which studies methods for digitally
synthesizing and manipulating visual content. Over the past decade, other specialized fields have
been developed like information visualization, and scientific visualization more concerned with
"the visualization of three dimensional phenomena (architectural, meteorological, medical,
biological, etc.), where the emphasis is on realistic renderings of volumes, surfaces, illumination
sources, and so forth, perhaps with a dynamic (time) component".
1.2 OpenGL
Originally developed by Silicon Graphics in the early '90s, OpenGL® has become the most
widely-used open graphics standard in the world. OpenGL is a software interface to graphics
hardware. This interface consists of about 150 distinct commands that you use to specify the
objects and operations needed to produce interactive three-dimensional applications. OpenGL
(Open Graphics Library) is basically a cross-language, multi-platform API for rendering 2D and
3D computer graphics. The API is typically used to interact with a GPU, to achieve hardware-
accelerated rendering .OpenGL serves two main purposes:
To hide the complexities of interfacing with different 3D accelerators, by presenting
the programmer with a single, uniform API.
To hide the differing capabilities of hardware platforms, by requiring that all
implementations support the full OpenGL feature set (using software emulation if
necessary).Some features of OpenGL include the following:
Geometric and raster primitives
RGBA or color index mode
Display list or immediate mode
Viewing and modelling transformations
Lighting and Shading
Hidden surface removal (Depth Buffer)
Texture Mapping OpenGL is a low-level, procedural API, requiring the programmer to
dictate the exact steps required to render a scene.
1.3 GLUT
GLUT is the OpenGL Utility Toolkit, a window system independent toolkit for writing
OpenGL programs. It implements a simple windowing application programming interface(API)
for OpenGL. The GLUT library has C, C++ (same as C), FORTRAN, and Ada programming
bindings. The GLUT source code distribution is portable to nearly all OpenGL implementations
and platforms. The current version is 3.7. Additional releases of the library are not
anticipated .The GLUT library supports the following functionality:
Multiple windows for OpenGL rendering.
Callback driven event processing.
An `idle' routine and timers.
Utility routines to generate various solid and wire frame objects.
Support for bitmap and stroke fonts.
Miscellaneous window management functions
Chapter 2
LITERATURE SURVEY
Computer graphics started with the display of data on hardcopy plotters and cathode ray
tube (CRT) screens soon after the introduction of computers.
OpenGL APIs: If we want to have a control on the flow of program and if we want to interact
with the window system then we use OpenGL API'S Vertices are represented in the same
manner internally, whether they are specified as two-dimensional or three- dimensional entities,
everything that we do are here will be equally valid in three dimensions. Although OpenGL is
easy to learn, compared with other APIs, it is nevertheless powerful. It supports the simple three-
dimensional programs and also supports the advanced rendering techniques.
GL/glut.h: We use a readily available library called the OpenGL Utility Toolkit (GLUT). which
provides the minimum functionality that should be expected in any modem windowing system.
The application program uses only GLUT functions and can be recompiled with the GLUT
library for other window system. OpenGL makes a heavy use of macros to increase code
readability and avoid the use of magic numbers. In most implementation, one of the include
lines.
Chapter 3
SYSTEM REQUIREMENTS
To be used efficiently, all computer software needs certain hardware components or other
software components to be present on a computer. These prerequisites are known as software
requirements. Though our graphics software does not demand strict specifications, certain basic
hardware and software requirements must be met.
Chapter 4
SYSTEM IMPLEMENTATION
4.1 OpenGL Functions:
The different OpenGL functions that are used in the project is described below: glClearColor
(0.0.0.0,0.0,1.0): - glClearColor () specifies the red, green, blue, and alpha values used by
glClear() to clear the color buffers. Values specified by glClearColor () are clamped to the range
0, 1
glEnd():- Delimit the vertices of a primitive or group of like primitives. glBegin and
glEnd delimit the vertices that define a primitive or a group of like primitives.
glutSwapBuffers():- glutSwapBuffers swaps the buffers of the current window if double
buffered. Performs a buffer swap on the layer in use for the current window. Specifically,
glutSwapBuffers promotes the contents of the back buffer of the layer in use of the
current window to become the contents of the front buffer. An implicit glFlush is done by
glutSwapBuffers before it returns. If the layer in use is not double buffered, glutSwap
Buffers has no effect.
glPushMatrix():- Push and pop the current matrix stack. There is a stack of matrices for
each of the matrix modes. The current matrix in any mode is the matrix on the top of the
stack for that mode. glPushMatrix pushes the current matrix stack down by one,
duplicating the current matrix. That is, after a glPushMatrix call, the matrix on top of the
stack is identical to the one below it.
glPopMatrix():- Push and pop the current matrix stack. glPopMatrix pops the current
matrix stack, replacing the current matrix with the one below it on the stack.
glTranslatef(50,100,0) Multiply the current matrix by translation a matrix. glTranslate
produces a translation by x y z. The current matrix is multiplied by this translation
matrix, with the product replacing the current matrix.
glutInit(&arge.argv) glutInit is used to initialize the GLUT library, glutlnit will initialize
the GLUT library and negotiate a session with the window system. During this process,
glutinit may cause the termination of the GLUT program with an error message to the
user if GLUT cannot be properly initialized. glutinit also processes command line
options, but the specific options parse are window system dependent.
glutInitDisplayMode(GLUT SINGLE GLUT_RGB) - Sets the initial display mode. The
initial display mode is used when creating top-level windows, sub windows, and overlays
to determine the OpenGL display mode for the to-be-created window or overlay.
glutInitWindowSize(1024,768) Set the initial window size. Windows created by
glutCreateWindow will be requested to be created with the current initial window
position and size. The initial value of the initial window size GLUT state is 300 by 300.
The initial window size components must be greater than zero. The intent of the initial
window position and size values is to provide a suggestion to the window system for a
window's initial size and position. The window system is not obligated to use this
information. A GLUT program should use the window's reshape call-back to determine
the true size of the window.
glutCreateWindow(“MOVING OBJECTS"):- Creates a top-level window. The name will
be provided to the window system as the window's name. The intent is that the window
system will label the window with the name, Implicitly, the current window is set to the
newly created window.
glutPositionWindow(0.0):- Requests a change to the position of the current window. For
top-level windows, the x and y parameters are pixel offsets from the screen origin. For
sub windows, the x and y parameters are pixel offsets from the window's parent window
origin.
glutDisplayFunc(display):-Registers the callback function (or event handler) for handling
window-paint event. The OpenGL graphic system calls back this handler when it receives
a window re-paint request. In the example, we register the function display() as the
handler.
glutKeyboardFunc(keyboard):-glutKeyboardFunc 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. The key callback parameter is the generated
ASCII character. The state of modifier keys such as Shift cannot be determined directly;
their only effect will be on the returned ASCII data.
glutMainLoop():-glutMainLoop enters the GLUT event processing loop. This routine
should be called at most once in a GLUT program. Once called, this routine will never
return. It will call as necessary any call backs that have been registered.
void display():-This function is used to display the start of the bus scene. It calls other
function like display20), display3() and display4(). It is also used to define and set the
colour. In the end there is a glflush() to display everything in the screen.
void front screen(void) This function is used to display the first page i. e topic of the
project and instructions.
Chapter 5
SYSTEM ANALYSIS
Object or Program Pipeline Object which provides the shaders for the programmable pipeline
stages
Chapter 6
SOURCE CODE
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <gl/glut.h>
#define UP 1
#define Down 2
#define LEFT 3
#define RIGHT 4
// Status Variables
GLint lvl = 1;
GLint points = 0;
GLint size = 0;
GLbyte gameOver = true;
GLbyte EnableLight = true;
// Snake Variables
GLint bodyPos[2][100] = {{}};
GLint _x = 5;
GLint _z = 10;
GLint _oldX[2] = {};
GLint _oldZ[2] = {};
GLbyte direction = 0;
// Food Variables
GLint _bx = 0;
GLint _bz = 0;
// Screen variables
GLint _w = 800;
GLint _h = 550;
GLint _Giw = 0;
GLint _Gih = 0;
GLint _Gfw = 150;
GLint _Gfh = 150;
glRasterPos2f(-40, 20);
Write("=========WELCOME TO Azzonika Tutorials=========");
glRasterPos2f(-6, 10);
Write("=========Simulation of Snake Game=========");
glRasterPos2f(-60, 0);
Write("=========To Start Playing please press 'S' or 's' =========");
}
void DrawSnake(){
int i;
glPushMatrix();
ManipulateViewAngle();
glTranslatef(bodyPos[0][i],-10.0,bodyPos[1][i]);//this will locate the spheres
glColor3f(1,0,0);//Color Red
glScalef(0.5,0.5,0.5);
glutSolidSphere(7,20,20);
glPopMatrix();
}
}
void DrawFood()
{
//Draw the Sphere representing the Food for the snake
glPushMatrix();
ManipulateViewAngle();
glTranslatef(_bx,-10.0,_bz);
glColor3f(1, 1, 0);
glScalef(0.5,0.5,0.5);
glutSolidSphere(7,20,20);
glPopMatrix();
}
void GameStatus(){
char tmp_str[40];
glColor3f(0.8, 0.2, 0);
glRasterPos2f(5, 20);
sprintf(tmp_str, "Snake Game");
Write(tmp_str);
// Print the status of the game on the screen
glColor3f(0, 0, 0);
glRasterPos2f(5, 10);
sprintf(tmp_str, "Level: %d Points: %d", lvl, points);
Write(tmp_str);
}
//Generates Random Numbers for the location of the food that the snake will eat
int RandomNumber(int high, int low)
{
return (rand() % (high-low))+low;
}
//Generate the New Food that the snake will eat
void newFood(){
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
_bx = RandomNumber(_Gfw-_Giw, _Giw+10);
_bz = RandomNumber(_Gfh-_Gih, _Gih+10);
}
//This Function Will Check for Collision
bool collision(){
int i;
for(i=0; i<size; i++){
if((bodyPos[0][i] == _x && bodyPos[1][i] == _z) ||
//((bodyPos[0][i] >= _x) && (bodyPos[0][i] <= _x + 5) && (bodyPos[1][i] >= _z) &&
(bodyPos[1][i] <= _z + 5)) ||
//((bodyPos[0][i] <= _x) && (bodyPos[0][i] >= _x - 5) && (bodyPos[1][i] <= _z) &&
(bodyPos[1][i] >= _z - 5)) ||
//((bodyPos[0][i] <= _x) && (bodyPos[0][i] >= _x - 5) && (bodyPos[1][i] >= _z) &&
(bodyPos[1][i] <= _z + 5)) ||
((bodyPos[0][i] >= _x) && (bodyPos[0][i] <= _x + 5) && (bodyPos[1][i] <= _z) &&
(bodyPos[1][i] >= _z - 5)))
return true;
}
return false;
}
}
//Checks for Collisoin if yes Game Over
if(collision()) gameOver = true;
//Checks if the snake ate the food (check the X and Y)
// If yes it will increase the points & the size of the snake & create a new food
if((_x == _bx && _z == _bz) ||
((_x >= _bx) && (_x <= _bx + 4) && (_z >= _bz) && (_z <= _bz + 4)) ||
((_x <= _bx) && (_x >= _bx - 4) && (_z <= _bz) && (_z >= _bz - 4)) ||
((_x <= _bx) && (_x >= _bx - 4) && (_z >= _bz) && (_z <= _bz + 4)) ||
((_x >= _bx) && (_x <= _bx + 4) && (_z <= _bz) && (_z >= _bz - 4))){
points++;
if(points < 100) size++;
if(points%5 == 0 && lvl < 15) lvl++;
newFood();
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if(EnableLight) initLight();
break;
case GLUT_KEY_DOWN :
if(direction != Down)
direction = UP;
break;
}
}
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 'S' : Reset() ;
glutPostRedisplay();
break;
case 's' : Reset() ;
glutPostRedisplay();
break;
//ESC to Exit
case 27:
exit(0);
break;
default:
break;
}
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(_w,_h);
glutInitWindowPosition(80,80);
glutCreateWindow("Snake Game");
Initialize();
glutSpecialFunc(Special);
glutKeyboardFunc(keyboard);
glutDisplayFunc(Display);
glutReshapeFunc(resize);
newFood();
Run(0);
glutMainLoop();
}
Chapter 7
SnapShots
Fig7.1
Fig7.2
Fig 7.6
Chapter 8
The Snake Game is a Good Way to Learn How to Recognize Patterns. Patterns have a
way of building academic skills, especially in the mathematical field. The Snake game is all
about patterns and how you can manipulate these patterns as the Snake gets longer.
8.2 References
Books
1. The Java Programming Language, by Ken Arnold, James Gosling, David HolmesADDISON-
WESLEY, 2000, ISBN 81-7808-148-2
2. Java Threads, Second Edition, by Scott Oaks, Henry WongO'REILLY, 1997, ISBN 81-7366-
057-3
3. Core Java – Volume I/II, Seventh Edition, by Cay S. Horst mann, Gary Cornell PEARSON
EDUCATION, 2005, ISBN 81-297-0932-5
4. Introduction to Algorithms, Second Edition, by Thomas H. Cormen, Charles E.
Leiserson, Ronald L. Rivest, Clifford SteinMIT PRESS, 2001, ISBN 81-203-2141-3
5. Head First Java, Second Edition, by Kathy Sierra, Bert BatesO'REILLY, May 2003, ISBN 81-
7366-602-4
Websites
1. Netbeans Community Docs
http://wiki.netbeans.org/wiki/view/CommunityDocs2.
2. The Inkscape Tutorials Blog
http://inkscapetutorials.wordpress.com/
3. Smashing Magazine – On line magazine for designers
http://www.smashingmagazine.com/
4. The Java Tutorials
http://java.sun.com/docs/books/tutorial/
5. Timing Framework
https://timingframework.dev.java.net/
6. JavaGaming.org's Forum
http://www.javagaming.org/forums/index.php
7. MIT Open Course Ware - 6.831 User Interface Design and Implementation
http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-831Fall-
2004/CourseHome/index.htm