Search Projects

Sunday, May 25, 2014

Formula One Racing Car Opengl Projects

One of the best thing to do in the Computer Graphics to develop a game, Formula One Racing Car is one to start. Everybody had heard about the Formula One Racing, it has high impact on people's entertainment. Most of the people like to see the fast running sports car. Michael Schumacher is one of the famous person in the Formula One, all of you may know him.

We need to learn Computer graphics to show some good graphics applications as well as some utilities for animation, games etc. Opengl computer graphics as per we read in VTU  6th sem syllabus, is very key to get in the touch with these things. It is starting step, so one need to go beyond it to become a graphics developer it would be key to start here. As we are talking today about the Car Racing games in OpenGL Projects, it not easy to go. I found some one had it built it in his own way.This may not be so complex or user friendly but quite good to start at this stage. If you go further OpenGL ES, which used in Android/iOS app development helps you alot. So my idea from this very project is to keep on learning and may be in future this could be a better achievement in your career to get you a high over others.

Coming to the project, this is a good car racing game like Formula one. Here you will see the car like of Formula one car with cylinder, the racing track of formula one. This project has few different view to look on the race.



Wednesday, May 14, 2014

Scaling in OpenGL

In this post I am going to show a simple way to learn how to do Scaling in OpenGL. Scaling is a property of transformation which helps increasing and decreasing the size of an object in computer graphics. The alteration in the size of object is done in each of the axis - X,Y and Z.

For Scaling in OpenGL we have inbuilt function which can be used easily on any 2d or 3d objects. The function  is -

Prototype :

void glScaled (GLdouble x,GLdouble  y,GLdouble  z);
void glScalef (GLfloat  x,GLfloat  y, GLfloat  z);

Sample :

glScalef (GLfloat  1.0f,GLfloat 0.5f , GLfloat  2.0f);

Here, in above sample code we see the function will scale the object into half in y direction, twice in z axis while remain same in x.

One thing is to be note is that - the matrix mode should be either GL_MODELVIEW or GL_PROJECTION, for object to be scaled.

Here is a sample program Which helps you understand the how the scaling works in perspective of  Opengl  computer graphics. This is simple c program, use x,y,z to scale down and X,Y,Z to increase scale factor in respective axis.

#include <gl/glut.h>

int x1 = 20.0f;
int y1 = 30.0f;
int x2 = 40.0f;
int y2 = 50.0f;
int x3 = 60.0f;
int y3 = 10.0f;

void Display()
{
 glClear(GL_COLOR_BUFFER_BIT);
 glPushMatrix();

    glBegin(GL_TRIANGLES);
    glColor3f(0.0f,0.0f,1.0f);

    glVertex3f(x1, y1, 0.0f);
    glVertex3f(x2, y2, 0.0f);
    glVertex3f(x3, y3, 0.0f);


    glEnd( );
    glPopMatrix();
    glFlush();
}
void MyKeyboard(unsigned char key,int mouseX,int mouseY)
{
    if (key == 'x')
    {
        glScaled (0.5f ,1.0f ,1.0f);
        glutPostRedisplay();
        return;
    }
else if (key == 'y')
{
glScaled (1.0f ,0.5f ,1.0f);
        glutPostRedisplay();
        return;
}
else if (key == 'z')
{
glScaled (1.0f ,1.0f ,0.5f);
        glutPostRedisplay();
        return;
}
else if (key == 'X')
    {
        glScaled (1.5f ,1.0f ,1.0f);
        glutPostRedisplay();
        return;
    }
else if (key == 'Y')
{
glScaled (1.0f ,1.5f ,1.0f);
        glutPostRedisplay();
        return;
}
else if (key == 'Z')
{
glScaled (1.0f ,1.0f ,1.5f);
        glutPostRedisplay();
        return;
}
else
{
glScaled (1.0f ,1.0f ,1.0f);
        glutPostRedisplay();
        return;
}

}

void main(int argc,char** argr)
{
 glutInit(&argc,argr);
 glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
 glutInitWindowSize(1000,600);
 glutInitWindowPosition(50,50);
 glutCreateWindow("The Scaling");
 glutDisplayFunc(Display);
 glutKeyboardFunc(MyKeyboard);

 glClearColor(0.0f,0.0f,0.0f,0.0f);
 gluOrtho2D(0.0,1000.0,0.0,600.0);
 glutMainLoop();
}

I think you get to know about the scaling transformation in OpenGL. For any question, query or suggestion put you comments.