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:
(http://farm4.static.flickr.com/3273/2899613865_76d7a65c7d.jpg?v=1222730402)
But mine ends up looking like this:
(http://s24.postimg.org/454so0sgl/Texture_Error_Screenshot.png)
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);
}
}
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.