Jump to content
  • Advertisement
Sign in to follow this  
little_changes

OpenGL texture mapping a .3ds object

This topic is 4584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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));
}

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!