True color TGA loading for MD2 Models

 

Copyright info

All code in this tutorial is protected by the [GPL License].
All text in this tutorial is protected by the [FDL License].

 

Tutorial by: Korax

Mailto: jkrige@ananzi.co.za

This is fairly easy.
Open the ref_gl.dll project. Open "gl_model.c" and look for the function called: R_RegisterModel().

Then after the line right in the beginning that reads:

 
 
dmdl_t *pheader;
 
     

...add right below it:

 
 
//jkrige - md2 tga loading
char md2skin[MAX_PATH];
//jkrige
 
     

Then... scroll down in this function till you find the lines reading:

 
 
for (i=0 ; i<pheader->num_skins ; i++)
          mod->skins[i] = GL_FindImage ((char *)pheader + pheader->ofs_skins +
i*MAX_SKINNAME, it_skin);
 
     

Replace them with:

 
 
//jkrige - md2 tga loading
i*MAX_SKINNAME, it_skin);
for (i=0 ; i<pheader->num_skins ; i++)
{
          COM_StripExtension((char *)pheader + pheader->ofs_skins +
          i*MAX_SKINNAME, md2skin);
          strcat(md2skin, ".tga");
          mod->skins[i] = GL_FindImage (md2skin, it_skin);
          if(!mod->skins[i])
          mod->skins[i] = GL_FindImage ((char *)pheader + pheader->ofs_skins +
          i*MAX_SKINNAME, it_skin);
}
//jkrige
 
     

*Wham-bam-thank-you-mam* and we are done! :)
All we need to do now is add corresponding TGA textures in the same fasion as per usual, and if the engine finds a TGA it'll load it, rather than the PCX if there is one. ;)

 

 

Tutorial Originally found at: