Jump to content
  • Advertisement
Sign in to follow this  

Texture problem with model loading

This topic is 4518 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 working on an OBJ model loader, but i'm having a weird problem. In the model I made both wings have the same texture, but they're mirror imaged. My loading program didn't acknowledge the mirror image and instead divided the rectangle-like polygon into two triangles and broke the texture in half. any help appreciated.

Share this post


Link to post
Share on other sites
Advertisement
You have to go into details of OBJ format and into detail of your loading program to see why is this happening. It seems that assigning or reading of texture coordinates is buggy...

Share this post


Link to post
Share on other sites
I took your advice and looked through the OBJ format again and reprinted all the data from my program to another text file to check it.

All my data is correct (as far as I can tell) and unfortunatly I couldn't find much on textures in OBJ/MTL files.

I took a screen shot of the problem. The left wing texture is supposed to be a mirror image of the right wing texture, but instead the texture was loaded on weird.

picture

here's my texture loading and drawing routines:

loading:
[source lang=cpp]
// texture coord
else if (buffer.substr(0, 2) == "vt")
{
// two values
sscanf_s(buffer.c_str(), "vt %f %f", &m_texcoords[TexCoordcount].u,
&m_texcoords[TexCoordcount].v);


TexCoordcount += 1;
}


drawing:
[source lang=cpp]
// set the Normals
glNormal3f( m_normals[m_faces.Normals[j]-1].x,
m_normals[m_faces.Normals[j]-1].y,
m_normals[m_faces.Normals[j]-1].z
);

// set UV coordinates
glTexCoord2f(m_texcoords[m_faces.TexCoords[j]-1].u,
//m_texcoords[m_faces.TexCoords[j]-1].u,
m_texcoords[m_faces.TexCoords[j]-1].v);

// set the Vertex point
glVertex3f( m_vertices[m_faces.Faces[j]-1].x,
m_vertices[m_faces.Faces[j]-1].y,
m_vertices[m_faces.Faces[j]-1].z
);

Share this post


Link to post
Share on other sites
OK, having stared at it long enough, i figured out part of the problem, it has to do with the order the vertices are drawn. I tried reversing the drawing loop and the wings switched. The right wing looked messed up and the left wing was drawn correctly (before it was the left wing drawn wrong, as stated in my above post).

I'm going to keep working on it but if someone could give me a hint I would appreciate it.

Thanks.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!