M2/Rendering a model

From wowdev
Jump to: navigation, search


When trying to render M2 geometry on screen, there are a few things to remember. Rather than shooting random bits of code at you, this page will explain all the process behind rendering M2s. This is all from my own experience. Some things might not be blizzlike, because I'm still learning this, and don't know everything; some things might be plain out wrong, because I don't know how to correctly make it happen. -- Warpten

This is not going to give you a step-by-step detailed way to render geometry and textures on screen. Consider it a general approach to M2 rendering.

All of the below has been done on Legion data files.

Drawing geometry and textures

Geometry is pretty straightforward: just push M2Vertex to the GPU.

As far as textures go, you need to be aware of a few things.

  • Type 0 - the simplest one to implement, since the path to the actual texture is embedded in the model.
  • Type 1 - Can be read from DB/CreatureDisplayInfoExtra
    • For Wrath, you basically have a direct string in that DBC.
    • For Legion, it gets technical.

Since Legion (or was it WoD) introduced HD textures, you have up to two texture FileDataIDs in here. For now, we will keep it simple, and use non-HD texture, since HD textures require parsing of another DBC to only push specifics parts of it to the GPU, one part for each render pass.

  • Type 2 - Cape texture.

For this one, you need to use DB/CharSections. GenType is 3, and you need to match gender, hair color, hair style, and race from DB/CreatureDisplayInfoExtra.


This one is very similar to type 6, except GenType becomes 2 and you need to match facial hair style, not hair style.


Again, much like 6 and 7, but GenType is 0.

  • Types 11, 12, and 13

These are read from CreatureDisplayInfo.TextureVariation[textureType - 11].

This should cover most uses of textures.