Overview
This class provides an API containing everything needed to load a quake2 (.MD2) model file and render it in OpenGL. Note that one instance of this class corresponds to one or two .MD2 files: a model and (optionally) a weapon. Skin image files must be in .PCX format. All memory management, drawing, animating, etc. is handled internally by the class.
Images
Here is a snapshot of a model rendered with realtime lighting, along with a test-driver I wrote:

Here is the same model without lighting, but with texturing

Here’s a snapshot of some sample log information about a loading model:

Videos
Here's a short video clip showing the above animated model, first in wireframe, then with lighting, then with skins, and finally with a weapon:API
Loads an .md2 model file. Once this has successfully completed, skins can be applied and the model can be drawn.
- modelFile should contain the filename of the .md2 file to load
- generateNormals indicates if lighting normals should be generated for this model.
- logProc can contain a pointer to a logging function, or NULL to suppress logging.
bool LoadCharacterModel(const char* modelFile, bool generateNormals, void (*logProc)(char*));
Frees the memory associated with our Quake2 Model, its textures, and its skins (if any)
void UnloadCharacterModel();
Loads a skin, applies it to the model, and loads it into OpenGL.
- skinFile must contain the filename of a .PCX image to apply as a texture.
bool LoadCharacterSkins( const char * skinFile);
Frees this model's materials from OpenGL and removes its associations to them. Once this has completed, a different skin may be loaded into the same model.
void UnloadCharacterSkins();
Loads any materials associated with this model into OpenGL. This is called automatically when a skin is loaded, but if the textures ever need to be REinitialized, this can be used.
bool InitCharacterMaterials();
Unloads materials from OpenGL, but leaves them associated with the model. This may be called if the user wants to re-load the same skins into OpenGL (see InitCharacterMaterials()).
void DeInitCharacterMaterials();
Loads a Quake2 Weapon, attatching it to the character's hand (initially without a skin)
- modelFile should be the *.md2 file of the weapon.
NOTE that for weapons to work, the weapon-model must have the EXACT same set of animations, each with the EXACT same names, number of frames, keyframes, and so forth.
bool LoadWeaponModel( const char * modelFile);
Frees the memory associated with our Quake2 weapon, and unloads its textures
void UnloadWeaponModel();
Loads a .PCX image and applies it to the Weapon model.
bool LoadWeaponSkins( const char * skinFile);
Frees this model's materials from OpenGL and removes its associations to them. Once this has completed, a different skin may be loaded into the same model.
void UnloadWeaponSkins();
Loads the model's skins into OpenGL. This is called automatically when a skin is loaded, but if the textures ever need to be REinitialized, this can be used.
bool InitWeaponMaterials();
Unloads materials from OpenGL, but leaves them associated with the model. This may be called if the user wants to re-load the same skins into OpenGL (see InitWeaponMaterials()).
void DeInitWeaponMaterials();
Animates the model! The animationSpeed parameter can be used to tweak how quickly each animation is displayed. Time-based movement is handled internally by the class, using animationSpeed only as a scalar. Returns the number of triangles rendered.
int DrawModel( int animationSpeed);
Sets the current animation to the animation specified by the index; If immediate is true, the change takes place instantly; else it switches once the current animation completes.
void SetAnimation( int index, bool immediate);
Cycles to the next animation. If immediate is true, the change takes place instantly; else it switches once the current animation completes.
void NextAnimation( bool immediate);
Sets its parameter to the name of the animation that's currently being displayed, and returns the number (index) of the current animation. -1 is returned if there is no animation. If the parameter is NULL, nothing will be copied there.
int GetCurrentAnimation( char *nameOut );
And there you have it! A quake 2 model loader.

Subscribe (RSS)
Recent Comments
09/8/2010 @ 7:50 pm
that sucks......way to stay focused tho
09/8/2010 @ 6:19 pm
sad tale
09/6/2010 @ 7:59 pm
Hahaha
09/6/2010 @ 11:38 am
Hi, Anyone know "these are the daves i know", by the kids in the hall? ;) Justin, I've also been doing some ...
09/5/2010 @ 9:21 pm
I did a little more digging and found out that I am only having this problem in Safari. I ...
09/5/2010 @ 3:15 pm
Great plugin
09/4/2010 @ 11:45 pm
I should also add that if i close out the window that opens when a user clicks the Facebook login ...
09/4/2010 @ 11:37 pm
Whenever I allow permission for Facebook it then opens the website I am using in the window instead of going ...
09/4/2010 @ 10:07 pm
"I can easily say that this was the bumpiest bus ride of my life." you have a short memory: ...
09/4/2010 @ 7:39 pm
Shopping mall!! No, I had no idea...it's not hard to believe considering the prime location...but I sure hope "used ...
09/4/2010 @ 6:50 pm
Hahahaha
09/4/2010 @ 5:46 pm
i had the exact same thought about corvinteto when i went - "this feels what an underground eastern european club ...
09/4/2010 @ 8:50 am
Hey Kareem...glad to see ur reading...hehe I was actually gonna point u in the direction of that post specifically (and ...
09/4/2010 @ 8:33 am
hey, I was just skimming the comments again and I see Kenneth Henderson posted a similar problem just before mine. Justin, ...