Search Projects

Showing posts with label Simple Project. Show all posts
Showing posts with label Simple Project. Show all posts

Friday, May 19, 2017

A Movable Car

For those of you, who want to have a very simple projects here we came a new but simple project. A Movable Car, unlike our car racing projects this is very simple projects, which include  only just a car. So, you will able to learn also how to draw a car from this project. We have also added a simple user interaction which allow user to move the car in all four directions with navigation keys.


A movable Car is very simple OpenGL C program, in which as show in figure we display a Car, which can be move in up,down, left and right with corresponding arrow key. The Car is drawn in red color to match it with Red Ferrari, and there black shield and windows. 

This program in opengl c/c++ is good for beginners, who want to learn opengl from scratch as it has tons of comments for almost all the lines, which highlights the use of each of the function or callbacks used. The function that we have used to draw the car, itself have all the comments which show the parts which are drawing whether it's roof, windows, bumper or skirt. In the comment the left or right side is also mentioned, which let you understand if it is of left or right part.

We have used only keyboard interaction for the user to move the car in the direction they want. In this opengl c programm we have used the function key for the first time. In almost all the use of function key was nil, we have used it here. You might be thinking it to be hard, but it is as normal as we implement return key or esc key for any action. Below is glimpse of how we have used  the function key.

if(key == GLUT_KEY_F2 )
{
//logic goes here
}

if(key == GLUT_KEY_F1 )
{
//logic goes here

Now you all understand how to use the function key. For all special functions visit opengl.org glutSpecialFunc documents.

Keyboard Interaction of Program

Below is description of what action car will perform when user press the mentioned keys.

Up - Car move forward
Down  - Allow to reverse the car
Right - Move in right direction
Left -  Move toward left direction
F1 -  Car turns right backwards
F2 - Car turns left backwards

Future Scope

For those of you, who want to develop something new by taking some code snippet. This project is for you. Download the free source code and develop some unique program like car racing game, car parking game, car simulator etc.

Source code

You can have free access to the source code o A Movable car opengl c++ program. Kindly download it by visiting the Download link. Share your experience, and creativity with the 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

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.

Sunday, February 28, 2016

Simple Opengl Program - Bouncing Ball

We have shared so many OpenGL Programs, today we are going to share a simple opengl program on Bouncing Ball. This program is simple, easy to code and understand as well, you can modify the program easily and made it into a superb project.

Simple Opengl Program - Bouncing Ball


Code Bouncing Ball C Program

Initialization

First we create a flag which will check the ball's uppermost position and lower most position. we will also define the coordinate of ball that varies as it bounce. The coordinate will be determine by a certain variable which changes the coordinate position by an amount which we fix. 

static int flag=0;
float tx=0.0,ty=0.0,tz=0.0;
float ball_x=0.5,ball_y=0.0,ball_z=0.0;

Draw and Update Ball

In this Simple Opengl Program we are going to create a procedure that will update the position of ball according to it's motion upward and downward. The function will use the variable flag as mentioned above. The update ball function will update the position of the ball of up and down. 

void updateBall()
{
    if(!flag)
    {
        ball_y+=0.05;
        if(ball_y>1.0)
            flag=1;
    }
    if(flag)
    {
        ball_y-=0.05;
        if(ball_y<-1)
            flag=0;
    }
}

In the draw function of this Simple Opengl Program we are going to draw the ball and make it bounce. Set current matrix on the stack and draw the Ball with the help of  glutSolidSphere. we call the Update function here so that the ball an change according to it's position going up or down. 

void display()
{
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     
        glClearColor(0,1,0,0);
     
       glPushMatrix();
     
        glBegin(GL_POLYGON);
            glColor3f(1,0,1);
         
            glVertex3f(-0.25,0,-1);

            glVertex3f(0.25,0,-1);

            glVertex3f(0,0.25,-1);
        glEnd();
        glPopMatrix();
 

        glPushMatrix();
            glColor3f(1,1,0);
            glTranslatef(ball_x,ball_y,ball_z);
            glutSolidSphere(0.3,60,23);
        glPopMatrix();

        updateBall();


        glutSwapBuffers();
}

Future Enchantments of Program

Drawing Ball

You can change the size of the ball by modifying the glutSolidSphere, color of the ball can also be modified similarly. Background of the color can also be added and changed accordingly. You an draw any new object in the background as the ball bounces.

What you can Modify

You can modify this Simple Opengl Program by adding some user interaction that will let ball start and stop. You can add sound to the program a well. The 3D version of the program can also be made as a future enchantments.   


Download the Simple OpenGL Program on Bouncing Ball.

Tuesday, August 9, 2011

A mini-project : Random Flowing lines (qix like)

Random Flowing lines


Description: An example of a 'qix'-like line demo, but without the traditional erase lines, and with anti-aliased lines. Draws a simple screen saver with colored lines moving in random fashion. The flow of lines make it beautiful.

USAGES: Right click and choose 'Full screen
' to view screen saver in Full screen mode and to have normal viewing choose 'Normal screen'. No other interactions.
To quit the program press 'Escape'


Project Code: Download

Monday, May 23, 2011

Motion Blur

Motion Blur


Description: The illustrate the Creation of a single component texture map with use of accumulation buffer for motion blur. A very simple Project to show off.

Usages: Right click and choose the two of the available options. Normal option return the image to Normal and the Motion Blur option cause to show the motion blur.

Project Code: Download