texture mapping a .3ds object

Started by
4 comments, last by darookie 18 years, 3 months ago
I'm a newbie in OpenGL. I don't know how to texture mapping an 3ds object by using the l3ds lib. I only can texture the object by an image I loaded; but I can't texture for it by the texture map which has been textured to the object by program anim09c. Please help me. .little.
Advertisement
I haven't used that API, but I think that the material specification for a 3D Studio object is stored in the 3ds file along with the geometry, so you just need to work out how to find out the file name of the texture applied to the mesh.
Each material will have a lot of different possible texture attachments, so you need to choose which one to use. I would recommend attaching your texture as the diffuse texture of the material you are applying to the mesh. Then in your program, read the mesh in, find out the name of the material attached to it, load the material, find out the file name of the texture that is set as the diffuse texture, load this file and apply it to your mesh.
Thank bluntman very much. I've tried and it runs well.
^^
My program runs so slowly. Please help me to optimize my code.
Thanks,
-little-

In the DrawGLScene(),to texture the object, I wrote:
======================================================

for (uint i= 0; i<scene.GetMeshCount(); i++)
{
LMesh &mesh = scene.GetMesh(i);
GLuint materialI = mesh.GetTriangle2(i).materialId;
LMaterial &material = scene.GetMaterial(materialI);

LoadGLTextures(material.GetTextureMap1().mapName, material.GetID());
glEnable(GL_TEXTURE_2D);
glBegin(GL_TRIANGLES);

for(uint j = 0; j < mesh.GetTriangleCount(); j++)
{
LTriangle2* triangle = &mesh.GetTriangle2(j);
for(int k=0; k < 3; k++)
{
glTexCoord2f(triangle->textureCoords[k].x, triangle->textureCoords[k].y);
glVertex3f(triangle->vertices[k].x, triangle->vertices[k].y, triangle->vertices[k].z);
}
}
glEnd();
glDisable(GL_TEXTURE_2D);

glVertexPointer(4, GL_FLOAT, 0, &mesh.GetVertex(0));
glNormalPointer(GL_FLOAT, 0, &mesh.GetNormal(0));
glColorPointer(3, GL_FLOAT, 0, &mesh.GetBinormal(0));
glDrawElements(GL_TRIANGLES, mesh.GetTriangleCount()*3,GL_UNSIGNED_SHORT, &mesh.GetTriangle(0));
}
you are using both immediate mode AND vertex arrays... only one of them is needed. :)

glBegin(GL_WHATEVA) is quite slow when the polycount increases... so try using only vertex arrays.

Peace!
"Game Maker For Life, probably never professional thou." =)
Quote:Original post by little_changes
LoadGLTextures(material.GetTextureMap1().mapName, material.GetID());

Make sure not to actually load textures each frame.
Load them on program startup and just bind the texture each frame.

This topic is closed to new replies.

Advertisement