Texture Coordinates in wrong order?

Started by fiendfan1, June 04, 2013, 23:36:29

Previous topic - Next topic

fiendfan1

I am texturing some models loaded through .OBJ and .MTL files, which are made into VBOs.

I am using triangulated faces (GL_TRIANGLES)

It ends up looking backwards.
For example an Ibanez logo should look like this:


But mine ends up looking like this:


The shader is just doing the following:
gl_TexCoord[0] = gl_MultiTexCoord0;

in the vertex shader

And
gl_FragColor = texture(textureID, gl_TexCoord[0].st);

in the fragment shader.

I load the model using this (psuedocode):
loop through lines of OBJ file
{
     if(line is specifying a texture coordinate)
     {
          listOfCoordinates.add(Coordinate);
     }
     else if(line is specifying a new face)
     {
           setup vertices, normals
           
           newface.textureCoords[0] = textureCoordsList.get(textureIndices.x - 1); // minus 1 because "lists" in OBJ files start at 1, arrays start at 0
           newface.textureCoords[1] = textureCoordsList.get(textureIndices.y - 1);
           newface.textureCoords[2] = textureCoordsList.get(textureIndices.z - 1);
     }
}

Fool Running

OpenGL textures have (0,0) at the bottom-left instead of the top-left. You either need to change your texture coordinates accordingly, or you need to flip your texture.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D