Reputation: 1784
I am having some difficulty loading in texture coords from the obj file using the GLM library
Using OpenGL 3.3
http://www.cs.manchester.ac.uk/ugt/COMP37111/glm/glm.h http://www.cs.manchester.ac.uk/ugt/COMP37111/glm/glm.c
I am under the impression that an obj file would have the same number of indexed (none repeated) vertexs as texture coords then the "GLMtriangle: Struct" would contain the vertexs "GLuint tindices[3]" that index the texturecoord array "texcoords". However the examples I have found do not have an equal number of texture coords to vertexs.
Using the above understanding I try to put all the texture coords in to an array by looping through each GLMtriangle and adding indexed texture coords to an array. To give me a texture coord for every single vertex.
C++ based pseudo code.
for (the number of GLMtriangles)
t= (the GLMtriangle index )
//vertex0
rawTextCoords[t] = GLMmodel->texcoords [GLMtriangle.tindices[0]];
rawTextCoords[t+1] = GLMmodel->texcoords [GLMtriangle.tindices[0]+1];
//vertex1
rawTextCoords[t+2] = GLMmodel->texcoords [GLMtriangle.tindices[1]];
rawTextCoords[t+3] = GLMmodel->texcoords [GLMtriangle.tindices[1]+1];
//vertex2
rawTextCoords[t+4] = GLMmodel->texcoords [GLMtriangle.tindices[2]];
rawTextCoords[t+5] = GLMmodel->texcoords [GLMtriangle.tindices[2]+1];
od
This is my current output.
Upvotes: 2
Views: 3427
Reputation: 13877
Your sample pseudocode at least looks sound.
Wild guess: you are not passing the proper values to glTexCoordPointer()
(or glVertexAttribPointer()
). It's easy to get the size
or type
values wrong if you type too fast. From your pseudocode size
needs to be 2.
Upvotes: 2