Search Projects

Monday, January 14, 2019

The Classroom CG lab Programs VTU

Preface 

OpenGL is used in the CG lab Programs VTU 6th SEM for learning the graphics. The aim of this blog is to give as much exposure to students so they can learn create and explore the new ideas of implementing the Computer graphics.

We have share many projects with free source code. We have also provided the free opengl tutorials in our blog. We have shre multiple programs snippets of c/c++ source code in OpenGL. There are many simple projects that can be used for large program with some library based program that can be complex in nature. With the same aim we have come up a program that act as the first part of our complex journey. We name the Program as  - "The Classroom".



Introduction

The Classroom CG lab Programs for VTU 6th SEM student comprised of showing jouney of education when we all are child and start learning the basics. This program will show the graphical representation of the the classroom where a teacher try to teaches student "A for apple B for Ball ...".

Components

CG lab Programs which  we have come up with have so many components or functions. These functions are basically code for small objects like roof, floor, blackboard tube light etc. Different parts of the classroom have different functions to create the objects.

We have created the lady teachers by using the different objects. Like the face we have used the circle to draw it. Similarly the hair we use the semi circle (created code for it). The other parts like nose we have use the lines and vertices with proper coordinates.

There are four kids which are facing towards the teachers has been rendered in this The Classroom CG lab Programs VTU 6th SEM. We have created two benches and each benches consist of two students. 

There is dark mode of the program where you can switch off the tubelight and whole class would be in dark.

User Interactions

n - to continues form start screen and proceed to next.
b- back to previous screen
r- restart the screen

Video Demo


Source Code

To get the source code write to openglprojects@gmail.com with the project title.

Sunday, August 26, 2018

OpenGL Chess Board in C++ with Source Code

Chess is interesting game with 8X8 checker of black and white. Hence we are going to see a program in OpenGL that implement Chess Board in C++ with free Source Code.

This program implements with the three functions:

1. Init function - this initalise the opengl program.
2. Chess Boards - this calculate the chess and sqaure and draw the same in the screen.
3.  Main function - this is the must and common program for each and every oepngl program.

chessboard() this function is used for the calculation of the end point of the cordinates of the box to make and is also mainly responsible for calling the drawSquare()
It is also a display function which is called from the main function which is responsible for sending graphics to the display window.

The forming of boxes is made through iterating first of all from 1st row and making 1st column then 2nd and then till 8th column as a single chessbord contains 8 column.

The similiar above operation is repeated till all the 8 rows have been iterated making a total 64 boxes (8 rows and 8 column).

The finally the chessboard() function contains a opengl glFlush()  which process all opengl routine as quickly as possible means it flushes all the matter on the display window for the next display.

This similar to our earlier chess board opengl program.

USE OF THE PROGRAM:

        The program OpenGL Chess Board in C++ can be use in the chess board game as well as in making the floor of the house or any other structure.

Source Code : 


#include<windows.h>
#include<glut.h>
int c = 0;
void init()
{
// For displaying the window color
glClearColor(0, 1, 1, 0);
// Choosing the type of projection
glMatrixMode(GL_PROJECTION);
// for setting the transformation which here is 2D
gluOrtho2D(0, 800, 0,600);
}

void drawSquare(GLint x1, GLint y1, GLint x2, GLint y2, GLint x3, GLint y3, GLint x4, GLint y4)
{
// if color is 0 then draw white box and change value of color = 1
if (c == 0)
{
glColor3f(1, 1, 1); // white color value is 1 1 1
c = 1;
}
// if color is 1 then draw black box and change value of color = 0
else
{
glColor3f(0, 0, 0); // black color value is 0 0 0
c = 0;
}

// Draw Square
glBegin(GL_POLYGON);
glVertex2i(x1, y1);
glVertex2i(x2, y2);
glVertex2i(x3, y3);
glVertex2i(x4, y4);
glEnd();
}
void chessboard()
{
glClear(GL_COLOR_BUFFER_BIT); // Clear display window
GLint x, y;

for (x = 0; x <= 800; x += 100)
{
for (y = 0; y <= 600; y += 75)
{
drawSquare(x, y + 75, x + 100, y + 75, x + 100, y, x, y);
}
}
// Process all OpenGL routine s as quickly as possible
glFlush();
}

int main(int agrc, char ** argv)
{
// Initialize GLUT
glutInit(&agrc, argv);
// Set display mode
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
// Set top - left display window position.
glutInitWindowPosition(100, 100);
// Set display window width and height
glutInitWindowSize(800, 600);
// Create display window with the given title
glutCreateWindow("Chess Board using OpenGL in C++");
// Execute initialization procedure
init();
// Send graphics to display window
glutDisplayFunc(chessboard);
// Display everything and wait.
glutMainLoop();
}

Wednesday, May 9, 2018

AirPlane Game Computer Graphics Project

In our blog we have seen many projects that deals with gaming. Today we are introducing one of the most complex game which we called the "AirPlane Game". It is not similar to copter game in openGL we have seen earlier. It is more complex and used SOIL.

Objective :

The objective of the project is to built a game using opengl and c++, which use the airplane as tool of game. The Computer Graphics game Project use playing have to run the airplane through the scene avoiding the danger as well as keeping the fuel up. As the fuel goes down user game ends, same when you hit by incoming object.

Features : 

1. Splash Screen 
2. Options to Choose the plane
3. Option to choose the scence
4. Different menu as mentioned below.

A menu with screen with the following items: 

• Play 
• Settings 
• Instructions 
• Credits 
• High Scores 
• Exit 

The game use SOIL to load the image hence you have to first set the soil in your project. 

For source code and documents email to openglprojects@gmail.com

Friday, April 6, 2018

OpenGL Code Traffic Signals

Presenting to you another OpenGL Code on Traffic Signals. We have already seen the Advance Traffic Signal OpenGL Program, now we will see another good program for same.


OpenGL Code Traffic Signals

Features 

The OpenGL Code  we presenting have many of the good features. Some of the features is listed below -

  1. Light Options - As in any traffic signal you will see the three lights - red, yellow and green. All the options has been implemented.
  2. Vehicles - To keep the OpenGL Code simple for all only three vehicles has been added. Though, if you like to add more do it, you are welcome.
  3. Lanes -  The right and left lane options is implemented in the program.
  4. User Interactions - Both mouse and keyboard interaction has been added to the OpenGL Code. All the user interactions has been listed in the post below.
  5. There is options to speed up the traffic is also in the code.
  6. Program has include the front page for introduction.

User Interactions

As mentioned earlier both mouse and keyboard user interaction has been added to this OpenGL Code. 
  • Keyboard Interactions
  1. Enter - From First Introduction screen to screen press Enter key at beginning.
  2. Help -  Press 'h'to get the help screen.
  3. Left to right movement - press 'l' to allow only left to right movement of traffic.
  4. Right to left movement - press 'r' to allow only right to left movement of traffic.
  5. Speed up - To speed up the traffic press 's'.
  • Mouse Interactions
  1. Left Mouse Button - This will stop the traffic as Red light gets on.
  2. Right Mouse Button (on hold) - Press right mouse button and keep on hold for yellow light. 
  3. Right Mouse Button (released) - After releasing the right mouse button the light changes from yellow to green and traffic moves.

Video Demo


Downloads

You can download the OpenGL Code from the Google Drive link.

Tuesday, April 3, 2018

Simple Travelling Salesman Problem (TSP) OpenGL Graphics Program

Many students looking for OpenGL Graphics Program for Travelling Salesman Problem (TSP), so we came up with it.

What is Travelling Salesman Problem (TSP)?

The Traveling Salesman Problem is problem where a traveler (or salesman) have to visit given no of cities, with known distance. Salesman have to visit each city once with and return to origin city with shortest possible distance.

The TSP is np-hard problem, where we have to optimized all the possible combinations.

Solutions

How to solve this problem?

In Computational world we solve this problem with two techniques - 1. Brute Force Approach and 2. Dynamic Programming.

1. Brute Force Approach - If we have n, no of cities then by brute force approach we will get (n-1)! permutations. We calculate cost (distance) of every permutation and record minimum cost for it. Finally return the permutation with minimum cost.  The time complexity for this method is n!.

2. Dynamic Programming - In this method we create the cost matrix and find the minimum cost.

Read the Dynamic Programming Approach for TSP.

Our Travelling Salesman Problem OpenGL Program

In our program we have restricted ourself to a maximum of 10000 cities. So, at begining user have to input the no of cities subjected to restriction, as mentioned. Each cities are represented as points. Lines joining the cities represent the distance. In initial setup the program creates sequence from the input, then distance is calculated. The swap and iterations are performs on the cities to find out the minimum distance.

You can see the image below - 



User Interaction

The initial distance is calculate at the beginning after user enter the no of cities in command line.
Next, there is two options for user -  key 's' and key  'a'.

When key 's' is pressed, two cities are selected randomly and swapped only when distance is minimum. This is performed as many times as 's' is pressed and distance calculated after swamp is shown in command line.

Pressing 'a', the swapping performed as many times for different cities(all). After performing each iterations the distance is shown in command line and finally it shows the minimum possible distance. Though this may not be the shortest path or minimum distance covered but optimal solution.