This simple opengl c program draws a car, allow user to move in all direction by pressing the navigation key.
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
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.
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.