A futuristic soapbox car in OpenGL for the course Computergraphics by Herman Crauwels (Campus De Nayer, KU Leuven). This application provides a demo for several OpenGL functions and is written in ANSI C.
- Basic car
- Basic finish
- Multiple 3D transformations (orthogonal, symmetric, ...)
- Multiple cars on the screen
- Show axes, light sources, ... controlled with a keyboard key
- Improved finish
- 4 different light sources
- Switch between several shade models
- Menu to configure the materials used to create the car
- Keyboard shortcuts
- Animates the wheels of the car
- Texture support of the finish and the car
- Toggle the alpha value of the car
- Fog support
See the inline comments in the source files for more information about the arguments of each function.
void menu(GLint id)
: Main menu callback to dispatch several other menus and handling the quit option.void coachworkMenu(GLint id)
: Coachwork menu callback to set the coachwork colors.void suspensionMenu(GLint id)
: Suspension menu callback to set the suspension colors.void finishMenu(GLint id)
: Finish menu callback to set the finish colors.void init(void)
: Init function to initialize several things before the OpenGL main loop has been started.void animation(GLint value)
: Callback forglutTimerFunc
to animate the soapbox car.void keyboardWatcher(unsigned char key, int x, int y)
: Keyboard callbackvoid displayFunction(void)
: Display callbackvoid windowFunction(GLint newWidth, GLint newHeight)
: Window callbackint main(int argc, char* argv[])
: Main function
void _drawFinishPart(GLint wireFrame)
: Private function to draw 1/4 of the finish arc.void drawFinish(GLint wireFrame, GLfloat* ambient, GLfloat* diffuse, GLfloat* specular, GLuint textureAddressing[], GLint texture, GLint checkpoints)
: Draws the complete finish arc.void drawCoachwork(GLint wireFrame, GLfloat* ambient, GLfloat* diffuse, GLfloat* specular, GLint clear, GLint checkpoints, GLint texture)
: Draws the coachwork.
void drawSuspension(GLint wireFrame, GLfloat* ambient, GLfloat* diffuse, GLfloat* specular)
: Draws the complete suspension.void drawTires(GLint wireFrame, GLfloat animationAngle, GLuint textureAddressing[], GLint texture)
: Draws the tires of the soapbox car.
void drawAxes(GLint axes)
: Draws the X,Y and Z-axis.void drawCheckpoint(const GLfloat* color)
: Draws a single checkpoint, used by the complex curves and light positions.void configureLights(GLint ambientLight, GLint diffuseLight, GLint specularLight, GLint spotLight, GLint spotAngle, GLint spotExponent, GLint spotHeight, GLint drawPositions)
: Configures the lights on the right position with the right colors.void configureFog(GLint fog, GLint fogMode, GLfloat far)
: Configures the fog and it's mode.
-
Right click to show the menu where you can select several materials for each component of the car.
-
You can also quit the application from the menu if you like.
Key | Description |
---|---|
x/X | Move camera (X axis +/-) |
y/Y | Move camera (Y axis +/-) |
z/Z | Move camera (Z axis +/-) |
i | Move camera to it's initial position |
1 | Toggle ambient light (GL_LIGHT0) |
2 | Toggle diffuse light (GL_LIGHT1) |
3 | Toggle specular light (GL_LIGHT2) |
4 | Toggle spot light (GL_LIGHT3) |
s | Switch to shading mode SMOOTH |
S | Switch to shading mode FLAT |
l | Turn wireframe mode ON |
L | Turn wireframe mode OFF |
j | Turn axes ON |
J | Turn axes OFF |
p | Turn light positions ON |
P | Turn light positions OFF |
k | Turn checkpoints ON |
K | Turn checkpoints OFF |
g | Toggle wheel animation |
G | Toggle car animation |
t | Toggle textures |
m | Toggle fog |
M | Toggle fog mode (LINEAR / EXP) |
n | Toggle competition mode |
f | Toggles coachwork transparency |
h/H | Moves the spot height (+/-) |
v/V | Manipulates the spot angle (+/-) |
w/W | Manipulates the spot exponent (+/-) |
b | Toggles light locking |
e/E | Manipulates the material shininess (+/-) |
q/Q | Quits the application |
- Clone this repo:
git clone https://github.com/DylanVanAssche/opengl-car.git
- Enter the directory:
cd opengl-car
- Install all OpenGL libraries via your package manager, you can find the dependencies in the MakeFile.
- Run
make
in the project directory. - Run
./car
to start the soapbox car.
-
Everything (except for the images,
initJPG.c
andinitJPG.h
) in this repository is available under the GPLv3 license. -
The images are available under separate licenses, see the folder
images
for more information. -
For
initJPG.c
andinitJPG.h
files, please check the comments in the files for more information.