texture coords and vertex arrays

Hey guys,

I’m working on a .obj loader and it works fine with glVertex3f calls but I’m trying to make the jump to vertex arrays.

The vertex, normal, and face indices seem to be working correct but I can’t seem to get the textures working. The texture is wrapped onto the object but in all the wrong places.

I’m just curious how the texture coords work with vertex arrays. Right now I define a (u,v) coord for each corner of each polygon just like when using glVertex3f.
So when I load texture coords into buffers I have a capacity of 1344 for 224 triangles (224 * 6 = 1344).
I am starting to get the feeling that maybe only one (u,v) coord can exist for each vertex. Is this true?

Well if anyone can shed any light on the situation it would be greatly appreciated.
thanks.

There is one UV coord pr vertex pr face.

Since some faces share vertexs. One vertex can have several UV coords :slight_smile:

I actually got it working using glDrawArrays. I couldn’t get it to work with glDrawElements.

To get it to work with glDrawArrays this is the code I used:

for (int i = 0; i < face[0].length; i++) {
bufferVertex.put(vertexX[face[0][i]]);
bufferVertex.put(vertexY[face[0][i]]);
bufferVertex.put(vertexZ[face[0][i]]);
bufferVertex.put(vertexX[face[1][i]]);
bufferVertex.put(vertexY[face[1][i]]);
bufferVertex.put(vertexZ[face[1][i]]);
bufferVertex.put(vertexX[face[2][i]]);
bufferVertex.put(vertexY[face[2][i]]);
bufferVertex.put(vertexZ[face[2][i]]);

  bufferNormal.put(normalX[faceNorm[0][i]]);
  bufferNormal.put(normalY[faceNorm[0][i]]);
  bufferNormal.put(normalZ[faceNorm[0][i]]);
  bufferNormal.put(normalX[faceNorm[1][i]]);
  bufferNormal.put(normalY[faceNorm[1][i]]);
  bufferNormal.put(normalZ[faceNorm[1][i]]);
  bufferNormal.put(normalX[faceNorm[2][i]]);
  bufferNormal.put(normalY[faceNorm[2][i]]);
  bufferNormal.put(normalZ[faceNorm[2][i]]);

}

for (int i = 0; i < faceTex[0].length; i++) {
bufferTexture.put(textureU[faceTex[0][i]]);
bufferTexture.put(textureV[faceTex[0][i]]);
bufferTexture.put(textureU[faceTex[1][i]]);
bufferTexture.put(textureV[faceTex[1][i]]);
bufferTexture.put(textureU[faceTex[2][i]]);
bufferTexture.put(textureV[faceTex[2][i]]);
}

bufferVertex.flip();
bufferTexture.flip();
bufferNormal.flip();
bufferIndice.flip();

GL11.glVertexPointer(3, 0, bufferVertex);
GL11.glNormalPointer(0, bufferNormal);
GL11.glTexCoordPointer(2, 0, bufferTexture);

Those face arrays contain the index of the vertex/normal/texcoord of the appropriate array. The 0,1,2 are for the three corners of the triangles.

Using this method I have multiple vertices that are the same in bufferVertex. I would rather use glDrawElements but I can’t seem to get that to work still. If anyone can help thanks in advance.

A guy on opengl.org gave me an idea to duplicate enough vertices so that its equal to the number of texture coordinates.

That pretty much sums up what I’m trying to deal with. What is the best way to draw a textured object when there are more texture coordinates than vertices?