문제

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

도움이 되었습니까?

해결책

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.

다른 팁

I've written a small library that parses .obj files, and includes sample code for rendering the model in OpenGL (LWJGL). The code to create the VBOs is hopefully fairly straightforward and clear enough to give you an idea of how it works, or you could just use the library, or cut and paste from it. (The license is public domain.) Take a look at it;

http://darksleep.com/oObjLoader/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top