It is Graphical Snake Game on linux based machine. It is developed in C using OpenGL.
Here I will tell you about OpenGL and How to install and run the OpenGL project?
Open Graphics Library (OpenGL) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics.
It is a Game where snake is moving on sceen. You have control to change the direction of snake. Real Game is that you have to increase our snake size and depending upon snake size score will be display. To increase snake size your snake have to eat food which will display randomly one by one on screen and if you eat your score will increase by one.You can also change the level from 1 to 9. Depending upon level snake speed will increase. Level 1 snake speed will be more than level 9 means 1 is highest level and 9 is lowest level
- Description : Snake game using OpenGL
- Technology : C and OpenGL
- Platform : Linux , Mac
We have use C language with OpenGl. We have use Double Circular link list to store (x,y) point of each cell of snake because we have no idea how much snake cell will be.
Below are instructions to install openGL on Ubuntu based Operating System. Put the below command on Linux Terminal.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install freeglut3
sudo apt-get install freeglut3-dev
sudo apt-get install binutils-gold
sudo apt-get install g++ cmake
sudo apt-get install libglew-dev
sudo apt-get install g++
sudo apt-get install mesa-common-dev
sudo apt-get install build-essential
sudo apt-get install libglew1.5-dev libglm-dev
g++ GameHeader.h
g++ snake.c -lGL -lGLU -lGLEW -lglut -o startGame
./startGame
-
#include<stdio.h>
: For Standard Input and output ( printf , scanf ) -
#include <stdlib.h>
: For Standard Libaray ( malloc , rand , srand) -
#include <time.h>
: For Time function ( nanosleep ) -
#include <GL/gl.h>
: Provides basic set of functions -
#include <GL/glu.h>
: Provides high level functions -
#include <GL/glut.h>
: Opening windows , managing menus and manging events
-
glutInit(&argc, argv);
Initializes the grahics toolkit -
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
Single display buffer and RGB mode -
glutInitWindowSize(640,480);
Initial window size -
glutInitWindowPosition(800,300);
Initial position of windows left corner -
glutCreateWindow("Snake Game");
Opens a window with title -
glutDisplayFunc(mydisplay);
Registering the display function -
glutSpecialFunc(mySpecialKeyboard);
Registering the special keyboard function ( like arrow key) -
glutKeyboardFunc(myKeyboard);
Registering the keyboard function -
glClearColor(0.127, 0.252, 0.0, 0.0);
Set the background color -
glClear(GL_COLOR_BUFFER_BIT);
Clear the entire window to background color -
glFlush();
The entire data is to be processed and sent for display -
glColor3f(0.0, 0.0, 0.0);
Set the drawing color to black; -
glRecti( x-5 , y-5 , x+5 , y+5 );
Draw the rectangle on screen -
glBegin(GL_TRIANGLES);
Specifies a set of points of triangle -
glVertex2i(x,y);
Giving the point with two integer arguments -
glutPostRedisplay();
Recall callback function