ms3d models with textures...

i know how to render ms3d models without textures… but, does anyone know how to render ms3d models with textures…

Theres nothing hard to render ms3d:s with textures, just make sure you have loaded the texture coordinates, and when I implemented it, I had to flip t vector.

The code goes like this:

for(i=0; inum_meshes; i++)
pmesh = &mdl->meshes[i];
pmaterial = &mdl->materials[pmesh->material_index];

  glBindTexture(GL_TEXTURE_2D, pmaterial->data->id);
  for(j=0; j<pmesh->num_triangles; j++)
  	ptriangle	= &mdl->triangles[pmesh->triangle_indices[j]];
  	for(k=0; k<3; k++)
  		glTexCoord2f(ptriangle->s[k], ptriangle->t[k]);


hmm… im haveing trouble understanding this… here is my code

typedef struct MS3D_HEADER_TYP
char id[10];
int version;

typedef struct MS3D_VERTEX_TYP
unsigned char flags;
unsigned char refCount;
char boneID;
float vertex[3];

typedef struct MS3D_TRIANGLE_TYP
unsigned short flags;
unsigned short vertexIndices[3];
float vertexNormals[3][3];
float u[3];
float v[3];
unsigned char smoothingGroup;
unsigned char groupIndex;
typedef struct MS3D_GROUP_TYP
unsigned char flags;
char name[32];
unsigned short numTriangles;
unsigned short
char materialIndex;
class MS3D
unsigned short numVertices;
unsigned short numTriangles;
MS3D_TRIANGLE* triangles;
unsigned short numGroups;
MS3D_GROUP* groups;

bool Load(char* filename);
void Render(void);

{ }

delete vertices;
delete triangles;
delete groups;
bool MS3D::
Load(char* filename)
FILE* file;
MS3D_HEADER header;
int loop;
if((file= fopen(filename, “rb”))==NULL)

return false;
fread(&, sizeof(char), 10, file);
fread(&header.version, 1, sizeof(int), file);
fread(&numVertices, sizeof(unsigned short), 1, file);
vertices= new MS3D_VERTEX [numVertices];
for(loop=0; loop<numVertices; loop++)
fread(&vertices[loop].flags, sizeof(BYTE), 1, file);
fread( vertices[loop].vertex, sizeof(float), 3, file);
fread(&vertices[loop].boneID, sizeof(char), 1, file);
fread(&vertices[loop].refCount, sizeof(BYTE), 1, file);
fread(&numTriangles, sizeof(unsigned short), 1, file);
triangles= new MS3D_TRIANGLE [numTriangles];
for(loop=0; loop<numTriangles; loop++)
fread(&triangles[loop].flags, sizeof(unsigned short), 1, file);
fread( triangles[loop].vertexIndices, sizeof(unsigned short), 3, file);
fread( triangles[loop].vertexNormals[0],sizeof(float), 3, file);
fread( triangles[loop].vertexNormals[1],sizeof(float), 3, file);
fread( triangles[loop].vertexNormals[2],sizeof(float), 3, file);
fread( triangles[loop].u, sizeof(float), 3, file);
fread( triangles[loop].v, sizeof(float), 3, file);
fread(&triangles[loop].smoothingGroup, sizeof(unsigned char), 1, file);
fread(&triangles[loop].groupIndex, sizeof(unsigned char), 1, file);
fread(&numGroups, sizeof(unsigned short), 1, file);
groups= new MS3D_GROUP [numGroups];
for(loop=0; loop<numGroups; loop++)
fread(&groups[loop].flags, sizeof(unsigned char), 1, file);
fread( groups[loop].name, sizeof(char), 32, file);
fread(&groups[loop].numTriangles,sizeof(unsigned short),1, file);

  groups[loop].triangleIndices=new unsigned short [groups[loop].numTriangles];

  fread( groups[loop].triangleIndices, sizeof(unsigned short), groups[loop].numTriangles,file);
  fread(&groups[loop].materialIndex,   sizeof(char), 1, file);


return true;
void MS3D::
int loop1;
int loop2;
int loop3;

// Draw By Group
for(loop1=0; loop1<numGroups; loop1++ )
// Draw As Regular Triangles, Since .MS3D’s Aren’t Optimized Like .MD2’s
for(loop2=0; loop2<groups[loop1].numTriangles; loop2++)
int triangleIndex = groups[loop1].triangleIndices[loop2];
const MS3D_TRIANGLE* tri= &triangles[triangleIndex];

  		// Loop Through The Triangle's Vertices, And Output Them!
  		for(loop3=0; loop3<3; loop3++)
  			int index= tri->vertexIndices[loop3];

  			glNormal3fv( tri->vertexNormals[loop3]);
  			glTexCoord2f(tri->u[loop3], tri->v[loop3]);


can you mix your code with mine to get it to work… (sorry that i ask so much)

Firstly, what kind of results do you get when you render using your code?

a model that is not textured

Your problem is simple, you have forgot to put glBindTexture before rendering the mesh.

You have to put a texture id variable to your material structure and load a texture for it at the loading stage.
Then bind the texture before rendering the mesh by doing:

glBindTexture(GL_TEXTURE_2D, materials[groups[loop].material_index].texture_id);

also make sure you have enabled texturing.

BTW, there’s a tutorial in NeHe’s site that also shows how to load/render MS3D model at

well this code wasn’t made for useing textures… i got this code from the nehe game tutorials on lesson 4… but how do i load the texture and alll the other stuff… im useing jpg for textures

NeHe has two tutorials for ms3d:s, and the one I posted shows how to load them and render using texturing.

I should say at this point that forget those JPGs, they’re way too complex, unless you want to link some lib with your app (DeVil).
Otherways I suggest using TGAs.

yea… i tried that one but when i put my own model in it it displays it without a texture… and i am useing the same kinda of texture as the tutorial… and when i opened the model in the tut in milkshape … the texture didnt show… but the material was there… please help