Search Projects

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



Sunday, March 13, 2016

Car Customization using opengl

Project Description



This project uses opengl standards along with C++ programming Language for Implementation. OpenGL is a graphics software system which has become a widely accepted standard for developing graphics application. OpenGL is a device independent graphics library that allows the programmer to use a common set of functions with an application. It provides the actual drawing tools through a collection of functions that are called within an application.

            This Application provides an interface for the user to design a car according to his custom needs. The user is provided with various options for modifying a car such as changing the colour, changing mirrors, removing them, etc. The user is provided an option to view the car in 3600by the click of the left mouse button.

            This application makes use of keyboard functions, mouse functions (for modification), and idle function (for rotation of car around 3600).


Note: since, the application has not been developed yet, we still don’t know about the various opengl functions used in this program.

This Abstract is written by - By Mohammed Abdul Aleem (4mh11cs046) and Manjunath N (4Mh11cs042).

Saturday, March 12, 2016

3D Jungle Viewer OpenGL Source Code and Report


Wonder what you can see in the image above. It is a Jungle isn't it? Looking Great?

We have seen so many 3D Projects in OpenGL, of which this project is wonderful and look more a professional, didn't let it feel that the project is developed by some students. The Project is developed by  UTBM students:  Thibaut Despoulain, Lauranne Didierjean, Baptiste Aubry and Adrien Mauranyapin. They Took more than 3 Months to develop is wonderful OpenGL Project.

The Project is nice work of pipelining in opengl, shaders, textures, framebuffers, composers, scene graph parsing in Opengl. They used many math library to accomplish the task along with the 3D modelling and texturing object appear in the 3D Jungle Viewer.

Download OpenGL Projects Source Code

You Can download this wonderful opengl project source code from GitHub .The complete source code, licensed under the MIT license, so you must obey the what licen says. You are free to distribute in any conditions, till you have the copyright information included.

OpenGL Project Report

The Project report is available free of code but is in French language. So If you need Translated Report  in english, do contact us to openglprojects@gmail.com. 


We give no warranty for Source code as well report, we are no way associated to them. We are not answers to your action. Please do read the Licence before using Code or report.

Watch Video Demo 

Thursday, March 10, 2016

Dual Rotating Triangle

In VTU 6th Sem Syllabus COMPUTER GRAPHICS AND VISUALIZATION Lab, Student have to do a project using the OpenGL and C++. Many of the student have made a great mark by submitting some good projects like 3D Animated Robot. Many of student want to have simple program, hence today we have came with very simple program for you.

Dual Rotating Triangle

As you may understand with the name of project, there is two triangle and they are rotating. We have used the simple code for developing this project. Let start doing it. First we have defined a global variable for angle.
int GAngle=0;


The whole program is divided into three parts - Display, Timer and Main. We will code each of them one by one. First We will define the Display Function, where we are going to use simple primitive opengl function for drawing triangle GL_TRIANGLE. We use the global GAngle variable to rotate the drawn triangle. You can experiment with the angle and try how it turn out to be. You can also experiments with the vertices coordinate which draw triangles.


void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glLoadIdentity();
glRotated(GAngle,0,1,0);

// Anti-Clockwise Winding
glBegin(GL_TRIANGLES);
glColor3f(1,0,0);
glVertex3f(-1,0,0);
glVertex3f(1,0,0);
glVertex3f(0,1,0);

glColor3f(0,1,0);
glVertex3f(-1,0,0.5);
glVertex3f(1,0,0.5);
glVertex3f(0,1,0.5);

glEnd();

GAngle = GAngle + 4;

glFlush();

glutSwapBuffers();
}


Now We add the Timer Function to let the Triangle turn on that time. Code is given below-


void Timer(int extra)
{
glutPostRedisplay();
glutTimerFunc(30,Timer,0);
}
Add main function and execute the program to get the output below.
int main(void)
{
// Init to double buffering

glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutCreateWindow("Dual Rotating Triangle");
glutDisplayFunc(Display);
glutTimerFunc(0,Timer,0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1,1,-1,1,1,3);
glTranslated(0,0,-2);
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
return 0;
}


Below is Full Source code for this Project, Just Copy Paste and run it. Before that there are few points for future enchantments -
  • Add Keyboard/Mouse Interaction to start and stop rotation of Triangles.
  • Use Keyboard/Mouse Interaction to Change the Color of the Triangles.


#include <stdio.h>

#include "glut.h"
int GAngle=0;
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glRotated(GAngle,0,1,0);

// Anti-Clockwise Winding

glBegin(GL_TRIANGLES);
glColor3f(1,0,0);
glVertex3f(-1,0,0);
glVertex3f(1,0,0);
glVertex3f(0,1,0);
glColor3f(0,1,0);
glVertex3f(-1,0,0.5);
glVertex3f(1,0,0.5);
glVertex3f(0,1,0.5);
glEnd();

GAngle = GAngle + 4;

glFlush();

glutSwapBuffers();

}

void Timer(int extra)
{
glutPostRedisplay();
glutTimerFunc(30,Timer,0);
}

int main(void)
{
// Init to double buffering

glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutCreateWindow("Dual Rotating Triangle");
glutDisplayFunc(Display);
glutTimerFunc(0,Timer,0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1,1,-1,1,1,3);
glTranslated(0,0,-2);
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
return 0;
}

Tuesday, March 8, 2016

Day Night Color

We have published a scenery program for java opengl graphics programming, in this post we are going to so you similar program but in C/C++. This program is somewhat same but not entirely same.

Download Our Android App from Google Play.


Day Night Color - OpenGL Program

We have name the program a Day Night Color because we can change the mode from Day to Night and vice versa. It is also a scenery program, where we have a house, mountain, tree, grass, sun and moon with stars.

Also View - 


When you first execute the program, you will find simple house and tree sketched with line in black background color. There is mouse interaction which will let swap between the Day and Night view.


Functionality of OpenGL Program

There are three mouse interaction added with use of menu. The three menu and their working is given below - 
  • quit - exit the program.
  • night color change - choose the night mode.
  • day color change -  select the day mode.
These menu will come when you will press the right mouse click. In day mode you will see sun and cloud, while in night mode stars and moon. House, Mountain and Tree will be same in both the mode. 

You can Download the OpenGL Program Source code.

Monday, March 7, 2016

Tower of Hanoi Simulation

In this Post we are going to see a powerful Tower of Hanoi Simulation with the help of OpenGL C graphics library. Tower of Hanoi Game is very old problem that open many opportunity for thinkers in solving the mysterious problems. We have already published Tower of Hanoi Game project, there are two of the Tower of Hanoi  opengl project which are different in user interface and way they get solve the problem. Now we are presenting this third project - Tower of Hanoi Simulation, you may select any of these and modify your self as well.


Statement of the projects - Tower of Hanoi Simulation

  • Some time it is necessary to display those object which are hidden from camera, hence in our project aims at displaying such objects using Memory chip using OpenGL.
  • Our aim is to draw attention of users toward computer graphics
  • Our aim is to create dominant project which is simple in use - Tower of Hanoi Simulation is one.

The benefits of this Tower of Hanoi Simulation are as follows:

  1. Simplicity: our project is easy and simple to use.
  2. Usability: it is easy to use and implement
  3. Flexibility: It is very flexible since it is easy to add new features to it
  4. Portable: It offers portability. It can be run anywhere any time
  1. Self learning: Coding of project itself is understandable to others.

UI Tower of Hanoi Simulation

KEYS ARE USED IN THE PROJECTS
  1. Press 1-9 to increase the number of disks.
  2. Press ‘r’ to reset.
  3. Press ‘f’ for fullscreen.
  4. Press ‘s’ to increase the speed.
  5. Press ‘x’ to decrease the speed.
SPECIAL FUNCTIONS used
  1. Press ‘page up’ to move the towers up.
  2. Press ‘page down’ to move the towers down.
  3. Press ‘up,down,left,right’ navigation keys to rotate the towers in upward, downward, clockwise and anticlock wise direction respectively.
MOUSE FUNSTIONS are used
  1. Press right button to zoom out.
  2. Press left button to zoom in
  3. Press middle button to reset.
This project on Tower of Hanoi Simulation is different then our previous two projects on Tower of Hanoi Game. It have more User Interface which allow user to interact with mouse and keyboards. You can easily choose the no of Disc as well. More views for better show off the screen.

If you want the Source code for this Project which is available at Rs 1000 (both source code and full documentation report ) contact 8147656011. Whatsapp us to 7022162923 or email to openglprojects@gmail.com.

Saturday, March 5, 2016

VTU Computer Graphics Projects - Mouse Effects

If you are a VTU 6th Sem Computer science student, then you have to submit in VTU Computer Graphics Projects. There are many Networking Based Projects which we have published on Our blog and there are many games as well. We have also published the Project for opengl mouse click example along with free source code. Today we comes with new program with the help of great functionality of mouse programming and we called it "Mouse Effects".

VTU Computer Graphics Projects

Many of student who search for VTU Computer Graphics Projects, are either looking for some simple program that has less opengl functionality used but there are many who go for advance programming in OpenGL C++. In this post we are going to show a project this is result out of some good knowledge of OpenGL C++ programming. In this Project we are going to show some effects on the screen with the help of Mouse. There will be some effect on the right click of mouse and some different on left click of mouse. Also we have use the Hold and release feature of mouse. 

VTU Computer Graphics Projects - Mouse Effects


Objective of Program :  To show effects with mouse click. 

Design Principle: We are going to design some particles which will be of various sizes, mainly the points in different sizes. These particles will have different colors and they will roam from one coordinate position to another on the screen. With left click of mouse, all these particles will get attracted toward the mouse click coordinate position. On the right click of mouse those particle repel away from the coordinate of mouse where click generated. 
There is another feature of program, when all the particles get attracted and struck at the position of mouse click, it can be drag to show a wonderful effect. You can view the effects in the Video Below. 

Future Enhancement : Nothing is perfect, hence there is always a new innovative idea can be apply to anything, same can be done to this VTU Computer Graphics Projects. You can add sound effect as well a explosion and more structure can be made via mouse. New shapes of particles can also be a good future enhancement.  

Contact us or post your email in the comment to get the Source code of the Project.

Thursday, March 3, 2016

3D Laptop Computer Graphics Programming in C

We have provided so many 3D opengl programs, today we are going to show you 3D Laptop Computer Graphics Programming in c.

What is CG Programming?

According to wikipedia  - "Cg (short for C for Graphics) is a high-level shading language developed by Nvidia in close collaboration with Microsoft for programming vertex and pixel shaders." Know more about the CG programming visit various sources including Nvidia.

Computer Graphics Programming in C

What is computer graphics programming? Computer graphics Programming is high level programming in various languages including C/C++. This programming teaches how to use the computer GPU and accelerate it for drawing various real object on computer screen. CG Programming is basically is done to convert real time object into computer graphics object. Like we are going to convert Laptop into an computer graphics object in this post via Computer Graphics Programming in c. There are many graphics library available to help and develop many programs through CG Programming. OpenGL library is one of them, which we are using our programs. There are many 3D projects including the 3D Bi-Cycle Computer Graphics Programming in C, 3D Robot OpenGL Program, 3D car racing game, Egg games etc. In all the above program we have used the C/C++ with OpenGL and came out with some fantastic project. We requested many of you to submit project you have developed, this 3D Laptop Computer Graphics Programming in c, is being submitted by one of our user. His name is Varun Sharma. He has developed this very good working 3D Laptop with so many features.

3D Laptop Computer Graphics Programming in c


Features of the Project -
  •  The laptop can be rotate along in x,y and z axis.
  • The Lid of the Laptop can be open/close.
  • Turn the screen of the laptop on/off.
  • Good looking 3D keyboard.
  • Show Text (Your name) on the Laptop Screen.


You can Download the 3D Laptop sample exe (for testing only) file by clicking the link given below -

3D Laptop – OpenGL CG project


You too can post you free or paid Project Here, Please Contact us.