Search Projects

Saturday, December 24, 2016

Fighter Jet CG Programs in C

There are many 2D program in our blog, today we are presenting Fighter Jet CG Programs in C. This cg opengl game look like video game. The game have a Fighter jet which moves in all direction and also fires bullets. User have control over the movement of jet and bullet.

Fighter Jet CG Programs in C


In this program the Fighter Jet is drawn with the help of simple line code using GL_LINE_STRIP and GL_LINE_LOOP. The Jet also have shield. The activation also is control by user with keyboard function. 

If the shield flag is turn on, drawshield() function is called. This will then activate shield. The shield is not shaped like cg opengl circle but some what similar to it. With sine and cosine functions and GL_LINE_LOOP it get close to circle. You can find cg opengl tutorial on circle in our blog. 

After Jet and Shield, next is bullet. In the Fighter Jet CG Programs in C GL_POINTS is used with for loop function to draw the bullet points. The entry flag set the entry point for bullet firing, allocate the bullet when to fire. The allocBullet function check if bullet is in use.

User Interaction Fighter Jet CG Programs in C

This cg Opengl program have keyboard interaction. Both alpha keys and navigation keys are allocated to the keyboard functions. 
ESC : Quit
S and s :
C and c : Show and Hide Cursor (More functionality is added by functions)
z and Z : Add 20 point in direction of motion.
f and F : Enter game mode.
l : Exit game mode
P and p : Pause the game
Q and q and Space : Fire bullet from fighter jet.

This cg opengl program have many keyboard functions. There are 4 keyboard functions  - key, keyup, special, specialup. 

Key function have the user interaction indicated above in the post. While in the Key function s, S setup the shield flag to one the same is set to keyup. Since different set of windows are created, it set the platform of shield and it's activation.  

The special and specialup function have up, left and right which give the thrust, left and right movement. 

Try downloading this program and execute. Give your feedback about it in comment.

Sunday, December 18, 2016

OpenGL Glut Create Menu Example

OpenGL Glut program can be mainly divided into 4 Parts. First part includes initialization with library and necessary files. Second Part include other necessary functions and third is the display functions which draw the object on screen. Final part is the main function. In this OpenGL Glut Create Menu Example, we will see these 4 parts separately.

This program will teach us how to add menu and submenu in opengl program. The menu can be created with click of right mouse button. In the OpenGL Glut Create Menu Example program menu and submenu in opengl id demonstration. The menu create have different types of structures whose color can be changed with selection of color in respective submenu.




FUNCTION USED

In this program we have three function - main, display, menu and createmenu used. We all know what main function do, so no tension about it. The function - display, menu and createmenu need to be understand.

The display function have all the code abou the objects that is going to show on the screen. The various object drawn are - Teaport, Torus, Sphere and Cone. Each of these objects are coded separately and placed in the display function. A global variable declared which helps in determination color and the object combination. Hence we are able to screen the objects in different colors as per the user selection in submenu. All these has been done with nested if else statement.

The createmenu Function lets us create menu and submenu. In main function first createmenu() is called. In the createmenu function glutCreateMenu(menu) is called for creation of each of the menu. Each selected menu entry passes the value passed for the callback.

Next is to add menu.The glutAddMenuEntry() function  will add the menu which passed to createmenu() along with the name of menu. For each menu a separate glutAddMenuEntry() function is required along with the different integer callback. If name of menu is same there will be now error while if integer callback is same, compiler error will show up.

Then we have glutAddSubMenu() function which create the submenu inside a menu item. It works in same way as glutAddMenuEntry() function. Different color is set in each of menu as submenu so that object in different color can be displayed.

OBJECTS USED IN THE PROGRAM

These are following functions used in the program along with the opengl functions.

  1. Teapot - glutSolidTeapot(r);
  2. Sphere - glutWireSphere(r, w, h);
  3. Torus - glutWireTorus(r, f, w, h);
  4. Cone - glutWireCone(r, f, w, h);
The color of each object used - Red,White,Yellow. Green and Blue attached with the menu in this OpenGL Glut Create Menu Example. Hence there are 5*4=20 objects can be drawn in display.

To trigger the menu and popup the menu, it can be attached to right or left mouse button with glutAttachMenu(). 

To attach it to right mouse button  - glutAttachMenu(GLUT_RIGHT_BUTTON);
To attach it to left mouse button - glutAttachMenu(GLUT_LEFT_BUTTON);


In our program we have used the GLUT_RIGHT_BUTTON so menu will appear on right click of mouse.

Download the source code.

Friday, December 2, 2016

2D game using OpenGL and Glut

You have seen a OpenGL Glut 3D Game by Mr. Jonathan Gonzalez Cortes of  FACULTAT D'INFORMÀTICA DE BARCELONA UPC - FIB Barcelona School of Informatics. He named the game as Ballenger. The game has so many features where user can play the game effectively. It was the single player game. Same Computer Engineer developed the 2D game using OpenGL and Glut. He named it as Tiny Quest. This game is more interesting and have more fun while playing. It will give you the feel of mario game, which you all might have played.

This game is also developed in C++ using OpenGL, with the use of the GLUT library. In the game custom GLSL shaders also used in the code. While the level design is original, the tilesets and sprites used are modified versions of the ones found in Sword of Mana.

Features of 2D game using OpenGL and Glut

There are two levels in the game.
There is animated players, enemies and the FX in the game.
The depth simulation is being done via Layered level design.
Smart challenging AI.
In the game you will find the meaningful audiovisual feedback.
There is Dynamic GUI.

View the video 2D game using OpenGL and Glut demo

 

If you have gone through the video, you might have get all the views about the game. Do share your observation as well as comments via our comment box below.

Download the source code, binaries and executable from the website.

Thursday, December 1, 2016

OpenGL Glut 3D Game

A Game - Ballenger OpenGL Glut 3D Game developed by Mr. Jonathan Gonzalez Cortes, Computer Science Engineer. The game name by him Ballenger developed during his academic at FACULTAT D'INFORMÀTICA DE BARCELONA UPC - FIB Barcelona School of Informatics. This OpenGL Glut 3D Game is single player skill game, with so many features.


OpenGL Glut 3D Game - Features 

  • The game have a wide range of area for exploring in 3D
  • There are about 16 Challengers in the game.
  • There are 5 keys in the game that can be collected by exploring in the game.
  • There are several check points which make the game more interesting and playable.
  • It used the original assets and design arts never used before.
  • One-way shortcuts to avoid undoing the paths taken
View the video demo of this OpenGL Glut 3D Game.


This interesting OpenGL Glut 3D Game is developed in C++ using the opengl.There is proper use of the GLUT library and custom GLSL shaders in this program. The world map and the models which were used in the game were designed in Photoshop and Blender. There are some problem in the game. The terrains and other parts get little litle strains. In some computer with less graphics the game may struck. The game may go slow in some computers as well.

You can download the source code and the executables from the website. Do comment about the game in the comment sections. Share your feedback as well.



Saturday, November 26, 2016

Multiplex - C++ graphics program

Multiplex is a place where you have multi screen to show various movies in different languages. Today we are going to have Multiplex - C++ graphics program. We have seen so many graphic programs in our website but this one something different from others. This program have so many features which we are going to explain below. This C++ graphics program has been developed using opengl graphics library in microsoft visual c++. You can use the same source code with some modification in the program like in linux or code blocks IDE.

Two Displays

This Multiplex - C++ graphics program divided into mainly to two different displays. First screen shows the entrance of multiples. In this display the multiplex theatre building with hoarding is shown in output of the program. In addition to the building a person, a car, trees and road is also displayed. To go inside the multiplex or enter the new display of execution left mouse button can be used.

Multiplex - C++ graphics program Theater View


In the second the ticket counter along with different screen of the theater is displayed. There is also a popcorn counter. This program is very interactive and takes input from user to display. As you enter the multiplex theater by pressing left mouse button you will have choice to choose you movies. Here to simplify things the movies or screen are named on the language- Hindi, English, Tamil and Kannada. Each screen has been give a specific key so when user press that key the person will enter the theater of assigned key. More user interactions are shown in below section of reading.

Multiplex - C++ graphics program - Screen View

Coding of C++/C graphics program

As already described above code of this c++ program used opengl graphics library. The code has been executed in windows platform using MS Visual studio. You can port this in different platform using some modification. This program is written in c++ opengl, hence it utilized the power of opengl primitive functions.
In this program a method name "box" is created. The snippet of same is shown below. These lines of code are very simple and easy to understand.

void box(int a,int b,int c,int d,int e,int f,int g,int h)

{
glBegin(GL_POLYGON);
glVertex2f(a,b);
glVertex2f(c,d);
glVertex2f(e,f);
glVertex2f(g,h);
glEnd();
}


If you know opengl then you might be aware of GL_POLYGON, it creates polygon of desired sides. The a,b,c,d,e,f,g,h are variable of coordinate can be used while calling the method.  Each object can be individually coded but using this method, you can save time as well reduce the length of program. This method saved many lines of codes.  In similar ways other objects like building, cars, trees etc has been coded.

User interaction

There are two way interaction in this program. This C++ graphics program used both Mouse and Keyboard to take  input from the user. Function for each keys and mouse is described below.

Mouse Interaction 

Left Mouse Button  - Press to go and view inside the multiplex theater.
Right Mouse Button - Press to exit from the multiplex anytime.

Keyboard Interaction

'm' to get inside theatre and go to ticket counter
'h' to go to hindi movie
'k' to go to kannada movie
't' to go to tamil movie
'e' to go to english movie
'p' to go to popcorn counter

Multiplex - C++ graphics program


Future Enhancement   

This program can be improved by converting this in 3D version. Also we can add many people instead of just a single person. Motion of person moving can also be added in future. Addition of sounds will also make this program fare improvement.

VIDEO DEMO

Source Code

To get the source code of this multiplex C++ graphics program shoot an email to openglprojects@gmail.com

Kindly Share your view about the program  via comments, or you can email us as well.

Saturday, November 5, 2016

“The Voyage”- Opengl Projects with source code and Report

We have seen so many c graphics projects on ship including the screen saver , the moving ship and opengl project on shrinking of ship due to iceberg collision. In this post you will get the opengl projects with source code and report on “Voyage".


“The Voyage”- Opengl Projects with source code and Report


Voyage is journey to other place using the sea routes. So in this c/c++ graphics project, has been aimed of showing a simple journey of people on a large ship over the sea. There is not much evolvement of too many parts of the journey, but only the movement of ship in the sea from one point to another. The simple journey over the sea has been shown.

Components in the c graphics projects

This opengl projects with source code and report has various components to display on the screen and demonstrate the voyage some of them are explained below with their coding samples.

1.       SKY : One of the prime component that has to be display on screen is sky,it has been shown in cyan color and used very simple coding. To make it realistic the horizon has been colored in white. 

Mountain : Another useful and distinguish component of this c graphics projects is mountain. With appropriate coordinate combination the hills of mountain has been designed and displayed. You need to point the correct x and y coordinate to draw the mountain on screen. Color of the mountain is selected to have a little brownish shade.

3.       Sea  : Without sea there is no meaning of Voyage, hence it is one of the important part of the c graphics projects. Off course the color of the sea is blue, and we have used many dots which make the sea seems flowing. The dots is along the rows with many rows.

4.       Ship : One of the important and integral component of this opengl projects with source code and report is ship. The have ship have three stores and each stores have their own compartments which is in decreasing order from bottom of the sea. Three air exhaust is also there at the top.

The only component in this project that shows motion is ship. The ship in this  c graphics projects moves from left part of the screen toward right, again it enter to some other parts of mountain region and travelling goes on.

Future scope

There are many thing you can add in this project few of them are mentioned below. If you have some idea that we are missing you can suggest us via comment to us.

  •  You can add sound of engines of ship
  •  Can control the ship with user interaction to start and stop the ship at certain time.
  •  Place trees along the mountains.
  • You can place small boats around the ship.
  • Fish or other sea animals can also be shown inside the sea.
The Voyage is one of finest opengl projects with source code and report available with us. To get this projects  with full source code along with the report including the ppt, shoot an email to openglprojects @gmail.com.

Monday, October 24, 2016

gRobot - Israel Student OpenGL Computer Graphics Program

The Open University of Israel, offers different courses under Computer Science discipline. Under it course catalogue - 20562 Computer Graphics is offered. The course is based on Computer Graphics with OpenGL (3rd ed.), by D. Hearn and M.P. Baker (Prentice-Hall, 2004). There is 4 credits for this course.

Under this course Computer Science students of Israel will able to learn about the computer graphics, different geometric perspective, geometrical coordinates and shapes, 2d and 3d objects - their representation using computer graphics,  transformation and rendering of objects etc. They will able to bring real life object onto the computer screen. The course have certain prerequisites - knowledge of mathematics and physics, able to imagine the two and three dimension objects.

One of the Student of Open University of Israel, Dennis Sheberla,  with his deep understanding on the subject brings a great output. He coded gRobot - OpenGL Computer Graphics Program. This program uses the OpenGL API.

gRobot - Israel Student OpenGL Computer Graphics Program

Features of the gRobot

  • A Robot with Forearms and Head with movement and rotations.
  • Wooden Textured floor
  • Good use of texture,ambients,lights, vectors etc in the image rendering.
  • Good use of camera and it's positioning. 
  • Use of interaction over the keyboard to control the movement of Robot.
  • There are different view modes.
  • Light source are also controllable.
  • There is also help text and menu appears with right mouse click.
Below is Information about the Controls and UI interactive with mouse and keyboards.

Controls

Mouse Control

Left click + movement - Control camera/robot viewing direction
Right click - Main Menu

Keyboard Control

Robot control

w - Move forward
s - Move backward
a - Move to left (Strafe left)
d - Move to right (Strafe right)
q, e - Rotate clockwise, counter clockwise
z, x - Rotate head left, right
c, v - Rotate head up, down
5, t (g, b) - Rotate right arm (left arm)
6, y (h, n) - Rotate right forearm (left forearm)
7, u (j, m) - Rotate right palm (left palm)

Camera Control

Arrow Up - Move forward
Arrow Down - Move backward
Arrow Left - Move left (Strafe left)
Arrow Right - Move right (Strafe right)
Page Up - Move camera upward
Page Down - Move camera downward

Color edit control

F2, F3 - increase/decrease bright (all colors)
F4, F5 - increase/decrease red color
F6, F7 - increase/decrease green color
F8, F9 - increase/decrease blue color
F10 - exit from color editing

Help

F1 - Show help
F10 - Exit from help

In the Program different classes has been used for different purpose, following is the brief information about them. 

Classes


·         Vector3 - Vector operations
·         TextureLoader - Loads textures, supports image different formats
·         Camera - Camera control
·         Robot - Robot control, draw and parameters
·         gRobot - Main program

The  Project's work of Dennis Sheberla, indeed is due to his hard work and determination for his Open University of Israel. You can take advantage from this by analysing source code and create you own wonderful program with it. We have done research and find some beautiful work from around the globe for your benifit.  You can find the source code of the program on GithHub.

Hope you liked this! Try this program by downloading it from the source and tell what you like about this. Also share you experience suggestion to us about this or any other program.

Friday, September 30, 2016

Rolling Blocks Simple Opengl Program

Rolling blocks is an simple opengl program in c written with the help of OpenGL API. It used the primitive function of OpenGL like for creating blocks in shape of rectangle GL_POLYGON is used. This is very basic program and meant manily for the beginners who want to learn and understand the concept of OpenGL. With the code snippet of this program you will be alble to use the very basic operation like how to draw a rectangle as well as use of translate and  push & pop matrix functions.

The Rolling blocks  is written in c and used the structure in it hence you must know about the structure in prior as well as have knowledge of Array. Structure with Array able to generate the program.


Now time for description of the program - this simple program will rolls out blocks from bottom of screen to upward and in random x directions. blocks will appear in x axis of the display while for moving we will make use of y coordinate. This 2D program so no use of Z axis. You are advice to make this program more attractive by converting the same into a 3D version. We have also put random color to blocks so it look nice and realistic.

Here is berif descrption of program
Define the structure

typedef struct rec
{
GLfloat x0,y0,x1,y1;
int color;
}block;
block

Now create the blocks and draw the same on screen

void createblocks()
{int i=0,y=-1000;
for(i=0;i<10;i++)
{
blocks[i].x0=rand()%500;
blocks[i].x1=blocks[i].x0+50;
blocks[i].y0=y;
blocks[i].y1=y+20;
blocks[i].color=rand()%3;
y+=100;
}
mode=1;
}
void drawblocks()
{int i=0;
for(i=0;i<10;i++)
{
glColor3fv(color[blocks[i].color]);
glBegin(GL_POLYGON);
glVertex2f(blocks[i].x0,blocks[i].y0);
glVertex2f(blocks[i].x0,blocks[i].y1);
glVertex2f(blocks[i].x1,blocks[i].y1);
glVertex2f(blocks[i].x1,blocks[i].y0);
glEnd();
}
}

Now the concept involving the program is over, just have to add the regular snippits like display function, init function and main function in the program which you might have done in many other opengl c programs.
There is twist that you need to use either mouse function or keyboard function to make rolling of blocks more interactive. In this program we have used the mouse function, while youare free to use keyboardrd program or modify the mouse function the way you want it to work.

The Source Code of whole program in C can be downloaded from Google Drive. 

Tuesday, August 23, 2016

Fish Hunting OpenGL Project

We have seen Aquarium Program in OpenGL C/C++ where there are many fishes, which can eat food to grow and produce more fishes. Similarly there was poison which will reduce the population of fish in the aquarium, hence keep on the population check of fishes in aquarium.  Fish Hunting/Fishing is another project which will involve the fishes. This project is submitted by KARTHIK S HANDE and GAGANDEEP L M of AIT, CHIKAMGALUR. The Concept is very nice and evolves phases of time.
The Concept
The Project Concept includes the drawing of river, man with fishing bow, fishing boat, fishes in river and surrounding mountains which includes the sun. Man will board on the boat and put the bow in river with food to attract the fishes. Fleshes will get caught through the fishing rod.
Implementation
The project is implemented using the OpenGL Primitive functions and c++ methods. There are some methods defined to give functionality for drawing the objects. Each method has their own job of completing the project aim.  The extract code which will draw the sun is given below –
void sun()
{

int i;
 GLfloat a[30][3],theta=0,delta=2*M_PI/30.0,r=2.0;
 glClear(GL_COLOR_BUFFER_BIT);
 glLoadIdentity();
  glTranslatef(0.7,6+y,0);
  glColor3f(1.0,0.6,0.0);
  for(i=0;i<30;i++)
  {
 a[i][0]=d+r*cos(theta);
 a[i][1]=y+r*sin(theta);
 a[i][2]=0;
 theta+=delta;
  }
  glBegin(GL_POLYGON);
  for(i=0;i<30;i++)
 glVertex3fv(a[i]);
  glEnd();
}
Similarly there different methods functions for other objects.
This project also includes the pre information page or say front page in other words. In the front page the information like project name, projects developers, coordinators, guides and college name are displayed.  With help of menu functionality provided by OpenGL , menu implementation is done to start the project.
For the User Interaction the mouse functionality has been used. The mouse event is not much broader but only to start the fishing page and exit the program. More functionality can be added to the project along with the implementation of keyboard beside use of mouse.
Hope you will like this simple and attractive project. Add something from your side and submit to us we will publish the same by giving your name.

Download the source code!

Saturday, July 9, 2016

Ping Pong Like Game in OpenGL C++

We have already seen the the Pong game in Computer Graphics OpenGL C++, in our previous post. In this post we are going to discuss about the Ping Pong Like game in OpenGL C++ which have a little difference from our previous ones. Only thing that differ in this game is that there is no computer on other side nor it is multiplayer game. It is simple single player game where player have to avoid the ball getting hit the down wall. It is similar to ping pong game in which ball moves from one player to others, if play unable to avoid collision of ball with the wall in his side he lose one point. In this game it is like same except there is no other opponent.


You can Download the Entire source code for this program from the link given below. If there is any error in the program do tell us, this programm is done on MS Visual Studio C++, in linux you need to modify it a bit and will work fine. You can change the program as per your need and do share the modified program to us.

Download Source Code

Monday, June 13, 2016

Spotlight's attenuation

Here we present another simple OpenGL Computer graphics C++ program. This is another spotlight program as previouly we have seen Spotlight swing. The program is similar but with a twist.
Description of the Spotlight's attenuation :

This program draws an array of spheres lit by a spotlight whose cone angle can be changed and which can be moved as well. The spotlight cone is shown by a wireframe. The spheres are colored using color material mode.

Interaction in Spotlight's attenuation:
Press the page up/down keys to increase/decrease the spotlight cone angle.
Press the arrow keys to move the spotlight.
Press 't/T' to decrease/increase the spotlight's attenuation.
Simple words we have so many balls of different colors lying on surface. There is a light source. We can move the light source and also able to decrease the diameter of the source with some keyboard interaction.

Future Enhancement of the Program :

1. We can remove the wire frame as light and give it a proper look.
2. Ball and other objects can also be added in the program.
3. Light source should also move up and down, can foucs at many different angle.
4. Whole Program can be converted into 3D version.
Do write about the program, if you have something to add to it or alter the program or a new version do send us to openglprojects@gmail.com. We welcomes your feedback, do comments and write to us.

Download the Source Code!

Sunday, May 22, 2016

Implement Stack and Queue

In this post I am going to give the OpenGL program on Stack and Queue. The implementation demonstration of Stack and Queue using the computer graphics and OpenGL API.

User can choose the operation and performs the task of Either Stack or Queue. The push, pop  can be perform in Stack, while insert, delete can be done on Queue. With the input from the user the task is perform and is based on the button pressed.



Download the source code.

Add or modify and tell use how you like this wonderful project.

Wednesday, May 18, 2016

Computer Graphics Projects on Machine Gun Recoil System

Developing Computer Graphics Projects with OpenGL is challenging task. It is more challenging when you see some high class projects of other. Today I am going to show you one of the finest Computer Graphics Projects made ever. The name of project is Machine Gun Recoil System.

Computer Graphics Projects on Machine Gun Recoil System

About Machine Gun Recoil System

In a recoil-based machine gun, it is mainly based on the moving mechanisms inside the gun which absorb some of the recoil force. Shaft moves as trigger is made and bullet crossed the nozzle to hit the target and next bullet get recoiled to the position of previous one. This helps the army person fires the bullets in continuous fashion to stop their enemy advancement or to kill the spy.

A computer graphics OpenGL Projects on the Machine Gun Recoil System is great idea to show the internal architecture of machine gun. Knowing the internal parts may helps its further development in future with more options for student keen in the area of defense.

To prepare this gun to fire, we pull the breech bolt back, so it pushes in the rear spring. The trigger sear catches onto the bolt and holds it in place. The feed system runs an ammunition belt through the gun, loading a cartridge into the breech.When we pull the trigger, it releases the bolt, and the spring drives the bolt forward.The bolt pushes the cartridge from the breech into the chamber. The impact of the bolt firing pin on the cartridge ignites the primer, which explodes the propellant, which drives the bullet down the barrel. The barrel and the bolt have a locking mechanism that fastens them together on impact.

The force of the moving bullet applies an opposite force on the barrel, pushing it and the bolt backward. 
As the bolt and barrel slide backward, they move past a metal piece that unlocks them. When the pieces separate, the barrel spring pushes the barrel forward, while the bolt keeps moving backward.The bolt is connected to an extractor, which removes the spent shell from the barrel. As the bolt recoils, the extractor slides with it, pulling the empty shell backward.The backward motion of the bolt also activates the ejection system. The ejector's job is to remove the spent shell from the extractor and drive it out of an ejection port.

Flow Diagram for How Machine Gun Recoil System Works

A very simple flow diagram in the form of a flowchart is shown in the figure which determines the working of Machine Gun Recoil System.


Future Additions for this Project

Even though demo designed is enriched with many options, it is a two dimensional demo, in future it can be re-designed with 3D animation and sound effects.

Buy this Premium Project by calling 7022162923/8147656011

Wednesday, April 27, 2016

OpenGL Clipping Plane Example

In this blog post we are going to learn about the usage of clipping planes in OpenGL.  This opengl clipping plane example will help you understand the basics of planes along with the axes. The program we are going to show is interactive as well as educative. It will helps you out where you will be able to formulate plane in space as well as able to create a clipping plane in OpenGL.


You might know many algorithm including the cohen sutherland line clipping algorithm, which is in the program list for Lab in VTU 6th Sem CSE CGV. The plane clipping algorithm is similar to that. You can Download the opengl clipping plane example source code and easily understand the program what it trying to do, easy to manipulate the algorithm.

Following is interactive function in the program (also printed in the program itself)-


1' - toggle x=0 halfplane
2' - toggle y=0 halfplane
3' - toggle z=0 halfplane
j', 'l' - translate x=0 halfplane (when toggled)
',', 'i' - translate y=0 halfplane (when toggled)
u', 'm' - translate z=0 halfplane (when toggled)
x', 'y', 'z' - reverse the corresponding half plane
-', '=' - rotate about y-axis
(Left/Right) mouse buttons - rotate about y-axis
[', ']' - rotate viewpoint about x-axis
f' - toggle fill/wireframe drawmode


Download the Full Source Code

Sunday, April 24, 2016

2d line Man OpenGL

There are many projects you are in 2d and many are in 3d. You might like 3d projects but there are few 2d projects which is very good not due to it's heavy coding but due to simplicity. There is no need to show off rather with some simple idea you can make the projects like we have the 2d line man.

The 2d line man is a very simple projects where with the help of line, the man figure is drawn. After drawing the figure it has been given the motion. You can see the demo in the below image.


\

Saturday, April 23, 2016

A Moving Mesh

Are you looking to something, that easy to implement for your CGV project?
Then you are here going to get a simple program you to can add something to it and make a good workable project. This program is called Moving Mesh.

The Moving mesh is like what we use to have in DD when TV lost the signal and we get a cross horizontal moving long rectangle in different color moving fast. You can view the same in image below.



Let Program the Moving Mesh

First we are going to add all the Header files and global variable will be declare.
#include<glut.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

static  GLdouble  viewer[]={0,0,5};
float dx=0.5,dy=0.5;
float angle=0;


To draw a mesh we are defining the mesh() function which uses the concept of looping and draw with help of vertices (primitive function). The code is given below -

void mesh()
{
float a=0.5,b=0.5,c=1;
            float  i, j;
            for(i=0;i<15;i+=dx)
            for(j=0;j<15;j+=dy)
            {
            glBegin(GL_POLYGON);
            glColor3f(a,b,c*fabs(sin(100*i+angle)));
            glVertex2f( i, j);
            glVertex2f( i+dx, j);
            glVertex2f( i+dx, j+dy);
            glVertex2f( i, j+dy);
            glVertex2f( i, j);
            glEnd();
            }
}
Now Display the Mesh with the display function as given below. Also we make sure the mesh continues to display and work well, we defined the idel and reshape functions.

void display()
{
            glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
            glLoadIdentity();
            gluLookAt(viewer[0],viewer[1],viewer[2],0,0,0,0,1,0);
            glTranslated(4,4,-5);
            mesh();
            glFlush();
            glutSwapBuffers();
} void idle()
{
angle++;
if(angle>360) angle=0;
glutPostRedisplay();
}
void myReshape(int w,int h)
{
            glViewport(0,0,w,h);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrtho(-2,20,-2,20,-10,20);
            glMatrixMode(GL_MODELVIEW);
}


Now time for the main program which is as usual almost same for all the C/C++ OpenGL Programs.

int main(int argc,char **argv)
{

glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("A Moving Mesh");
glutDisplayFunc(display);
glutReshapeFunc(myReshape);
glutIdleFunc(idle);
glClearColor(1.0,1.0,1.0,1.0);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 0;
}


You can add something to this program and make it interactive, like a keyboard or mouse function to start and stop motion.

Monday, April 18, 2016

Copter Computer Graphics Game Project

A Computer Graphics Mini PROJECT ON COPTER GAME Submitted in partial fulfillment of the requirements for the award of degree of Bachelor of Engineeringin Computer Science and Engineering - Submitted by SANTHOSH of Vivekananda Institute of Technology, GUDIMAVU, KUMBALGODU Bangalore.

This Computer graphics Project is inpired by most famous game on Android - Flappy Birds.It is similar to that insded of touch, we are using mouse button and bird is replaced by the helicopter.


SOFTWARE REQUIREMENTS SPECIFICATION:


This section attempts to bring out the requirements and specifications as given out by the Vishweshwaraiah Technological University for the completion of the package.

Minimum requirements expected are cursor movement, editing picture objects  like point, line, circle, ellipse and polygons. Transformations on objects/selected area should be possible.. User should be able to open the package do the required opearations and exit from the environment.
Good user interface, which can be GUI ,Menu based, should be provided.. Should use all most all the graphical input technologies for efficient programming and interact through various input devices. Should be a device independent package that is able to compile and create an executable.

EXTERNAL INTERFACE REQUIREMENTS:


User Interface:   

The interface for the 2D package  requires for the user to have a mouse connected, and the corresponding drivers software and header files installed.

For the convenience of the user, there are menus and sub –menus  displayed on the screen.

Menus

The Menus  consists of various operations related to drawing on the area specified. It also has the 'clear' option for clearing the screen and also change the background color.
Palettes Color palette, which displays the different colors available to the user. He/she can pick the required color by clicking anywhere in the window specified.

Hardware Interface:

The standard output device, as mentioned earlier has been assumed to be a color monitor. It is quite essential for any graphics package to have this, as provision of color options to the user is a must. The mouse, the main input device, has to be functional. A keyboard is also required.
Apart from these hardware requirements, there should be sufficient hard disk space and primary memory available for proper working of the package.

Software Interface:

The editor has been implemented on the windows platform and mainly requires an appropriate version of the compiler to be installed and functional. Though it has been implemented on windows, it is pretty much platform independent with the restriction that there is support for the execution of C++ files.

IMPLEMENTATION


This project developed uses basic Brute force methods to work. This contains a varying x-coordinate and y-coordinate for every point of the object drawn with two variables holding 0 displacements initially.

This displacement decreases if mouse is passive else if left mouse button is held down then x-displacement is increased and if right mouse button is held down y-displacement is increased hence the copter is controlled on the scenario.



The same is with the obstacles, there are 4 pre-defined obstacles and a random function which selects one of the 4 pre-defined obstacles which has to be released and there is no y displacement for the obstacles. There may be at the most two obstacles at any given time which are controlled by two index variables. Switching is of the variables is done whenever an obstacle leaves the scene.

There are two limits one at the top and the other at the bottom whose values are updated every time according to the location of the copter  i.e. whether the copter is above or below an obstacle or not. There are 2 more limits which are unaffected one is to the right extremity and other to the left extremity which note that the chopper does not go beyond the window extremes.

A function is maintained so as to display the score of the player. Here we have made use of concepts of translation and scaling along with use of push and pop matrix functions and conversion of integer to ascii for displaying numbers.

We have even used a temporary file so as to maintain track of the high score scored, the file gets created if it does not exist and initializes the high score to 0 for the first time after which the high score is automatically read from the temporary file.

We have maintained an exit flag so as to take decision whether the player is still playing or whether he is out in the game so as to control the end of the game. If this flag is set the players score is shown on the output screen.

We use the concept of Double buffering so as to avoid flickering image rendering. A mouse function is used for giving input interfacing.

Maintenance & Future Enhancements:   

Improved memory requirements may allow us to introduce more obstacles and other external environments.
This may also be upgraded to develop 3-D aircraft simulations using 3-D model and some concepts of physics, lighting and perspective vision which were hindered in the current project due to time constraints.
This may also be interfaced with keyboard for movement and mouse for shooting thus implementing flight war game.
This may also be upgraded with sound effects so as to bring it to the interest of the user.

Source code and Report


You can purchase this Project source code along with the Report at a minimal Cost of Rs 400 via Bank Transfer(Detials on the Payment page) or Rs 500 via Mobikwik or Paytm to mobileno 7022162923. To contact us before doing the payment else there will be delay in delivery.

Sunday, April 10, 2016

Airplane Takeoff computer graphics projects

Airplane Landing opengl projects for vtu computer graphics lab.
This simple opengl computer graphics program in which, the airplane do a take off in the air. After take off the airplane fly in air. This a very simple program as explain will show airplane take off from it's runway.

Airplane Takeoff computer graphics projects

As seen in the figure from the output of the Airplane Takeoff computer graphics projects, c program you can see the three objects - sky, airplane and runway. All these objects are designed with simple opengl graphics objects. Do download the projects and tell us if you have something to add to it, we are going to publish the modified program on this blog.

Download the Program.

Sunday, March 27, 2016

OpenGL Tutorial 2D Moving Car

In this post we are going to learn opengl tutorial on 2D Moving Car. This is very simple tutorial on opengl, which will teach how to make use of simple polygon functions. You can see the final output of below.

OpenGL Tutorial 2D Moving Car


We are going to make the 2D Car with simple polygon - triangle, quadrilateral and circle. In this opengl tutorial we are going to use these three simple polygon to create the car. Since we are going to make moving Car, hence first going to define the angle of movement.

/* rotation angle for the triangle. */
float rtri = 0.0f;

/* rotation angle for the quadrilateral. */
float rquad = 0.0f;

Next step is to create a function that will generate the wheel of car.

void drawBall(void) {
        glColor3f(0.0, 1.0, 0.0); //set ball colour
        glTranslatef(ballX,ballY,ballZ); //moving it toward the screen a bit on creation
        //glRotatef(ballX,ballX,ballY,ballZ);
        glutSolidSphere (0.3, 20, 20); //create ball.
        glTranslatef(ballX+1.5,ballY,ballZ); //moving it toward the screen a bit on creation
        glutSolidSphere (0.3, 20, 20); //
        }

Draw Rest part of Car

We are going to draw the rest of the car with the display functions in our opengl tutorial. 
/* The main drawing function. */
void DrawGLScene()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        // Clear The Screen And The Depth Buffer
  glLoadIdentity();                // Reset The View

  glTranslatef(rtri,0.0f,-6.0f);        // Move Left 1.5 Units And Into The Screen 6.0
   
  //glRotatef(rtri,1.0f,0.0f,0.0f);        // Rotate The Triangle On The Y axis
  // draw a triangle (in smooth coloring mode)
  glBegin(GL_POLYGON);                // start drawing a polygon
  glColor3f(1.0f,0.0f,0.0f);            // Set The Color To Red
  glVertex3f(-1.0f, 1.0f, 0.0f);        // Top left
  glVertex3f(0.4f, 1.0f, 0.0f);
  
  glVertex3f(1.0f, 0.4f, 0.0f);
  
  glColor3f(0.0f,1.0f,0.0f);            // Set The Color To Green
  glVertex3f( 1.0f,0.0f, 0.0f);        // Bottom Right
  glColor3f(0.0f,0.0f,1.0f);            // Set The Color To Blue
  glVertex3f(-1.0f,0.0f, 0.0f);// Bottom Left    

  //glVertex3f();
  glEnd();                    // we're done with the polygon (smooth color interpolation)
  drawBall();
 
  rtri+=0.005f;                    // Increase The Rotation Variable For The Triangle
  if(rtri>2)
      rtri=-2.0f;
  rquad-=15.0f;                    // Decrease The Rotation Variable For The Quad

  // swap the buffers to display, since double buffering is used.
  glutSwapBuffers();
}


Now you need to have the init functions, window resize function, simple keyboard and main functions. We have included all the function and create the program for this opengl tutorial.  See the full source code for the program given below.


#include     // Header File For The GLUT Library 
#include     // Header File For The OpenGL32 Library
#include     // Header File For The GLu32 Library
//#include      // Header File For sleeping.

/* ASCII code for the escape key. */
#define ESCAPE 27

/* The number of our GLUT window */
int window; 

/* rotation angle for the triangle. */
float rtri = 0.0f;

/* rotation angle for the quadrilateral. */
float rquad = 0.0f;

/* A general OpenGL initialization function.  Sets all of the initial parameters. */
// We call this right after our OpenGL window is created.
void InitGL(int Width, int Height)         
{
  // This Will Clear The Background Color To Black
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);     
  glClearDepth(1.0);                // Enables Clearing Of The Depth Buffer
  glDepthFunc(GL_LESS);                // The Type Of Depth Test To Do
  glEnable(GL_DEPTH_TEST);            // Enables Depth Testing
  glShadeModel(GL_SMOOTH);            // Enables Smooth Color Shading

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();                // Reset The Projection Matrix

  gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);  

  glMatrixMode(GL_MODELVIEW);
}

/* The function called when our window is resized (which shouldn't happen, because we're fullscreen) */
void ReSizeGLScene(int Width, int Height)
{
  if (Height==0)                // Prevent A Divide By Zero If The Window Is Too Small
    Height=1;

  glViewport(0, 0, Width, Height);        // Reset The Current Viewport And Perspective Transformation

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
  glMatrixMode(GL_MODELVIEW);
}

float ballX = -0.5f;
float ballY = 0.0f;
float ballZ = 0.0f;

void drawBall(void) {
        glColor3f(0.0, 1.0, 0.0); //set ball colour
        glTranslatef(ballX,ballY,ballZ); //moving it toward the screen a bit on creation
        //glRotatef(ballX,ballX,ballY,ballZ);
        glutSolidSphere (0.3, 20, 20); //create ball.
        glTranslatef(ballX+1.5,ballY,ballZ); //moving it toward the screen a bit on creation
        glutSolidSphere (0.3, 20, 20); //
        }


/* The main drawing function. */
void DrawGLScene()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        // Clear The Screen And The Depth Buffer
  glLoadIdentity();                // Reset The View

  glTranslatef(rtri,0.0f,-6.0f);        // Move Left 1.5 Units And Into The Screen 6.0
   
  //glRotatef(rtri,1.0f,0.0f,0.0f);        // Rotate The Triangle On The Y axis
  // draw a triangle (in smooth coloring mode)
  glBegin(GL_POLYGON);                // start drawing a polygon
  glColor3f(1.0f,0.0f,0.0f);            // Set The Color To Red
  glVertex3f(-1.0f, 1.0f, 0.0f);        // Top left
  glVertex3f(0.4f, 1.0f, 0.0f);
  
  glVertex3f(1.0f, 0.4f, 0.0f);
  
  glColor3f(0.0f,1.0f,0.0f);            // Set The Color To Green
  glVertex3f( 1.0f,0.0f, 0.0f);        // Bottom Right
  glColor3f(0.0f,0.0f,1.0f);            // Set The Color To Blue
  glVertex3f(-1.0f,0.0f, 0.0f);// Bottom Left    

  //glVertex3f();
  glEnd();                    // we're done with the polygon (smooth color interpolation)
  drawBall();
 
  rtri+=0.005f;                    // Increase The Rotation Variable For The Triangle
  if(rtri>2)
      rtri=-2.0f;
  rquad-=15.0f;                    // Decrease The Rotation Variable For The Quad

  // swap the buffers to display, since double buffering is used.
  glutSwapBuffers();
}

/* The function called whenever a key is pressed. */
void keyPressed(unsigned char key, int x, int y) 
{
    /* sleep to avoid thrashing this procedure */
   // usleep(100);

    /* If escape is pressed, kill everything. */
    if (key == ESCAPE) 
    { 
    /* shut down our window */
    glutDestroyWindow(window);
   
    /* exit the program...normal termination. */
    exit(0);                  
    }
}

int main(int argc, char **argv) 
{  
  glutInit(&argc, argv);  

  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);  

  /* get a 640 x 480 window */
  glutInitWindowSize(640, 480);  

  /* the window starts at the upper left corner of the screen */
  glutInitWindowPosition(0, 0);  

  /* Open a window */  
  window = glutCreateWindow("Moving Car");  

  /* Register the function to do all our OpenGL drawing. */
  glutDisplayFunc(&DrawGLScene);  

  /* Go fullscreen.  This is as soon as possible. */
  //glutFullScreen();

  /* Even if there are no events, redraw our gl scene. */
  glutIdleFunc(&DrawGLScene);

  /* Register the function called when our window is resized. */
  glutReshapeFunc(&ReSizeGLScene);

  /* Register the function called when the keyboard is pressed. */
  glutKeyboardFunc(&keyPressed);

  /* Initialize our window. */
  InitGL(640, 480);
  
  /* Start Event Processing Engine */  
  glutMainLoop();  

  return 1;
}

Monday, March 14, 2016

GRAPHICAL IMPLEMENTATION OF ATLAS

1.1   About Computer Graphics
            The term computer graphics has been used in a broad sense to describe "almost everything on computers that is not text or sound". 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, see study of computer graphics
Computer graphics are graphics created using computers and, more generally, the representation and manipulation of image developments in computer graphics have had a profound impact on many types of media and have revolutionized animation, movies and the video game industry.
1.2 IMAGE TYPES        
 

2D computer graphics are the computer-based generation of digital images—mostly from two-dimensional models, such as 2D geometric models, text, and digital images, and by techniques specific to them Pixel art


Pixel art is a form of digital art, created through the use of raster graphics software, where images are edited on the pixel level. Graphics in most old (or relatively limited) computer and video games, graphing calculator games, and many mobile phone games are mostly pixel art.

Vector graphics formats are complementary to raster graphics. Raster graphics is the representation of images as an array of pixels and is typically used for the representation of photographic images.  Vector graphics consists in encoding information about shapes and colors that comprise the image, which can allow for 3D computer graphics in contrast to 2D computer graphics are graphics that use a three-dimensional representation of geometric data that is stored in the computer for the purposes of performing calculations and rendering 2D images. Such images may be for later display or for real-time viewing’s more flexibility in rendering.
1.3   Open GL
OpenGL is the premier environment for developing portable, interactive 2D and 3D graphics applications. Since its introduction in 1992, OpenGL has become the industry's most widely used and supported 2D and 3D graphics application programming interface (API), bringing thousands of applications to a wide variety of computer platforms. OpenGL fosters innovation and speeds application development by incorporating a broad set of rendering, texture mapping, special effects, and other powerful visualization functions. Developers can leverage the power of OpenGL across all popular desktop and workstation platforms, ensuring wide application deployment.
OpenGl runs on every major operating system including Mac OS, OS/2, UNIX, Win32/64, Linux, OPEN Step and BeOS as well as embedded real time Oss and game consoles. It is callable from Ada, C, C++, FORTRAN, and java and offers complete independence from network protocols and topologies.
1.4   About Project 

            This mini project “ATLAS” provides us with the information   about countries, their capitals and flags.  It can be considered a subset of a real life atlas.  It is an interactive project, since it allows the user to pick the country of his/her choice and know all about it.  The user first of all arrives at a main screen after which he can select a continent of his/her choice. Further he will be led to a set of countries which are present in the selected continent. Amongst the set provided the user can select a country. The name, capital and flag of the country will be displayed on screen.. He/she can traverse through the countries and their flags with help of suitable menus provided. 



   Design
            The complete overview of the project is shown in the block diagram; it shows how it will perform actions through out its execution.
The design depicted in the figure 3.1 specifies that initially the user is provided with a menu of continents. Amongst these the user selects one using the mouse interface. Further the Sub-menu of countries within the selected  continent is displayed. Amongst these the user again selects one country  using the mouse. Finally the flag of the county is displayed along with the county’s name and its capital.

3.2 Algorithm
Step 1: Start
Step 2:  Initialize and specify the size, position and creates the output window.
Step 3:Specify the view volume
Step 4: Create a menu for users
Step 5:Create an interaction for the user to select from the menu
Step 6:Create the respective flags.
Step 7: Stop