View Full Version : ms3d models with textures...

08-16-2002, 04:09 PM
i know how to render ms3d models without textures.... but, does anyone know how to render ms3d models with textures....

08-17-2002, 09:36 AM
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; i<mdl->num_meshes; i++)
pmesh = &amp;mdl->meshes[i];
pmaterial = &amp;mdl->materials[pmesh->material_index];

glBindTexture(GL_TEXTURE_2D, pmaterial->data->id);

for(j=0; j<pmesh->num_triangles; j++)
ptriangle = &amp;mdl->triangles[pmesh->triangle_indices[j]];

for(k=0; k<3; k++)
glTexCoord2f(ptriangle->s[k], ptriangle->t[k]);

08-17-2002, 09:42 AM
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* triangleIndices;
char materialIndex;
class MS3D
unsigned short numVertices;
MS3D_VERTEX* vertices;
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(&amp;header.id, sizeof(char), 10, file);
fread(&amp;header.version, 1, sizeof(int), file);
fread(&amp;numVertices, sizeof(unsigned short), 1, file);
vertices= new MS3D_VERTEX [numVertices];
for(loop=0; loop<numVertices; loop++)
fread(&amp;vertices[loop].flags, sizeof(BYTE), 1, file);
fread( vertices[loop].vertex, sizeof(float), 3, file);
fread(&amp;vertices[loop].boneID, sizeof(char), 1, file);
fread(&amp;vertices[loop].refCount, sizeof(BYTE), 1, file);
fread(&amp;numTriangles, sizeof(unsigned short), 1, file);
triangles= new MS3D_TRIANGLE [numTriangles];
for(loop=0; loop<numTriangles; loop++)
fread(&amp;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(&amp;triangles[loop].smoothingGroup, sizeof(unsigned char), 1, file);
fread(&amp;triangles[loop].groupIndex, sizeof(unsigned char), 1, file);
fread(&amp;numGroups, sizeof(unsigned short), 1, file);
groups= new MS3D_GROUP [numGroups];
for(loop=0; loop<numGroups; loop++)
fread(&amp;groups[loop].flags, sizeof(unsigned char), 1, file);
fread( groups[loop].name, sizeof(char), 32, file);
fread(&amp;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(&amp;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= &amp;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) http://www.opengl.org/discussion_boards/ubb/smile.gif

08-17-2002, 10:11 AM
Firstly, what kind of results do you get when you render using your code?

08-17-2002, 10:52 AM
a model that is not textured

08-17-2002, 11:03 AM
Your problem is simple, you have forgot to put glBindTexture before rendering the mesh.

08-17-2002, 11:06 AM
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.

08-17-2002, 11:08 AM
BTW, there's a tutorial in NeHe's site that also shows how to load/render MS3D model at http://nehe.gamedev.net/tutorials/lesson.asp?l=31

08-17-2002, 11:38 AM
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

08-18-2002, 08:38 AM
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.

08-19-2002, 04:11 PM
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