views:

42

answers:

1

I've written an OBJ loader which parses the vertices, texture coords, and normals, each are stored in a FloatBuffer, and passed to opengl:

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, fbVertices);
gl.glNormalPointer(GL10.GL_FLOAT, 0, fbNormals);

However I am stumped as to how i am supposed to pass my index buffer to glDrawElements, I've read that the index will refer to the index in the array for the vertices, texture, and normals, but upon reading the OBJ file description, it seems that faces are stored in a format such as this:

f 1/2/3 4/5/6 7/8/9

with the format being

vertice/texture/normal

glDrawElements only accepts 1 index, which should refer to all 3, but when i look at an actual OBJ file, this doesn't seem possible. How do you pass the index for all 3?

You can find a copy of the code here: http://codepad.org/melc1HIC

+1  A: 

You can't directly, you need to do some preprocessing before passing the data to OpenGL, so only one index is used for each vertex, and this index also works for texture coordinates, normals, etc.

Matias Valdenegro
How? Wouldn't it be easier to have the modeling package do this? I just can't figure out how to export in a more "opengl friendly" manner, or if this is normal.
SilverLogic
Sure, but you would have to use another format, that's how OBJ files are structured.
Matias Valdenegro