3
votes

I'm developing an Android application with OpenGL ES 2.0.

I want to load an export made with Blender 2.49b in Wavefront OBJ format. I have identified verxtex position, normal and texture.

I want to use glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) to draw my mesh but I don't know how I can obtain the last parameter, indices, from a Wavefront OBJ file.

Are faces the 'indices' that I'm looking for?

I've found this on a forum: faces = indices starting with 1!

What is the meaning of 'starting with 1!'?

Thanks.

2

2 Answers

4
votes

It means the first index is 1 instead of zero. Java/C arrays/collections use zero based indicies and the first element starts with zero. Wavefront OBJ format indexes start with 1.

faces are made up for 3 values v/vt/vn which are indexes. The indexes are not specified directly in the file format. Instead it's the order in which the v, vt, vn elements occur in the file. So as you are parsing the file you have to keep track of how many vertexes, vertex texture, and vertex normals you have encountered.

For all the details on the format you'll want to consult the spec.

http://www.martinreddy.net/gfx/3d/OBJ.spec

0
votes

There are no indices in the wavefront .obj format. You are the one that specifies the indices when you load the mesh data from the file. What I'd do is:

iterate per face:
    iterate every vertex of a face
        assign index here when you store the data to your own project's vector

In other words for each of these lines:

f 3/55/23 34/2/12 34/43/128
f ...

for each triple of attributes introduce a new vertex (to be stored in the vertex buffer) and a new index (to be stored in the index buffer).