IQM info: http://sauerbraten.org/iqm/
IQM format description (structs referenced below): http://sauerbraten.org/iqm/iqm.txt
unsigned char *fileData;
example_read_file_function( &fileData );
struct iqmheader *header = (struct iqmheader *)fileData;
There are 3 × num_triangles
uint32_t vertex indexes at IQM file + ofs_triangles
. Upload as an OpenGL GL_ELEMENTS_BUFFER
buffer object.
uint32_t *indexes = (uint32_t*)( fileData + header->ofs_triangles );
// number of indexes: header->num_triangles*3;
iqmvertexarray are at IQM file + ofs_vertexarrays
. Look through and find ones you want (IQM_POSITION, etc) then interleave the arrays (position, normal, texcoords, ... repeating for each vertex) for uploading to OpenGL as an GL_ARRAY_BUFFER
buffer object.
[See IQM gpu-demo link below.]
Meshes have material name at IQM file + header->ofs_text + mesh->material
and triangle & vertex range for rendering.
struct iqmmesh *mesh = (struct iqmmesh*)( fileData + header->ofs_meshes );
for ( uint32_t i = 0; i < header->num_meshes, mesh++ ) {
// loop though all meshes
char *meshName = (char *)( fileData + header->ofs_text + mesh->name );
char *meshMaterial = (char *)( fileData + header->ofs_text + mesh->material );
}
- IQM gpu-demo
- Mesh tutorial -- glVertexAttribPointer( X , ... ) refers to X in the Shaders tutorial.
After uploading indexes and vertex data you have to bind vertex attributes so the shader knows where the position, etc are in the vertex buffer object [see Mesh tutorial]. You also have to bind the vertex attribute name/index for the GLSL shader [See Shaders tutorial]. Though all of that is general OpenGL stuff.
The above should give you unanimated IQM support. To apply skeleton transform you need vertex attributes for bone joint blend indexes and weights [vertex buffer and shader], upload bone joint transform matrices [relative change from IQM::joints aka the bind pose] to OpenGL shader uniform before drawing mesh, and calculate vertex transform matrix in GLSL shader.