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:

img1

Here is the same model without lighting, but with texturing

img2

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

img3

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.

Contact | Terms & Privacy
©2004-2018 Justin Klein
whos online
Feedburner
HTML5 Valid
07-19-2018 13:31:18UTC 0.18s 48q 4.98MB