Quake 2 Model Rendering

By mid June 2010 I worked on a personal project that consisted in rendering models from the classic Quake 2 game by Id Software. Here’s a video of the renderer.



Quake 2 was one of my favorite games when I was young and researching how to load and render its 3D models instantly sent me down the nostalgia path.

For those who might be interested in developing their own loader, Quake 2 models are very easy to read and parse from languages such as C and C++. This is mostly because .md2 files consist in a binary file format that we can easily read into C structs.

David Henry does a great job at explaining how the bytes are stored internally, so I’m not going to reproduce his work here. Nonetheless, here’s the md2 file header:

struct md2_header
{
     int id;
     int version;

     int skinwidth;
     int skinheight;

     int framesize;

     int numskins;
     int numvertices;
     int numtexcoords;
     int numtriangles;
     int numglcmds;
     int numframes;

     int skinDataOffset;
     int textureDataOffset;
     int triangleDataOffset;
     int frameDataOffset;
     int glcmdsDataOffset;
     int endOffset;
 };

Quake 2 model files organize vertices and triangles into keyframes: a series of poses that enable us to draw the model animated. The texture to use when rendering the model is referenced by the file too. Each file might point to zero or more textures in the PCX format. Textures are called the model’s “skin” in Quake 2’s terminology.

The video above were generated using the custom renderer that I wrote. It is using OpenGL and GLUT to create the window and draw the model.

Now, you’ve probably noticed that the animation in the video above looks rather “choppy”. It’s definitely not smooth. The reason is that keyframes provide a base for animating the model, but not enough frames are provided as to produce a “continuous” animation.

In my next post I’m going to show you how we can improve this situation. Stay tuned!

One thought on “Quake 2 Model Rendering

  1. I am very interested in your model rendering code for my url http://rlogin.dk/quake2/newbie-guide/servers

    I got male/grunt.pcx and male/grunt_i.pcx

    convert grunt.pcx grunt.jpg works, so grunt.pcx is just a normal image format it seems

    but the output is a flat image, I need a 3d rendered image
    preferably without using opengl to convert — cli just like ‘convert(1)’ does

    do you mind sharing your source/putting it on github
    I want to contribuet on it, I have been using C for 15 years but I dont feel like inventing it from new really
    I would like to make a functional program for this though…

Comments are closed.