Obj Decoder &

Started by
0 comments, last by Krohm 16 years, 8 months ago
I'm trying to write a simple wavefront obj decoder and I have come to a block. Here's a sample from my obj file:
Quote: #384 vertices, 764 faces v 0.81895431 0.99238976 -0.81895431 v 0.88494427 0.96555492 -0.81914344 ... .. vt 0.26794330 0.59115951 vt 0.26829364 0.59066995 ... .. vn 0.28871099 0.91284825 -0.28871099 vn 0.45619804 0.84870605 -0.26754697 ... .. f 1/55/1 381/56/381 2/49/2 f 2/49/2 4/51/4 1/55/1 ... ..
Where I'm having issue is in understanding what to do with the last two lines for rendering. Obj files define the last two lines like so: f v0/vt0/vn0 v1/vt1/vn1 v2/vt2/vn2, where v=vertext, vt=vertex texture coord, vn=vertex normal. When my arrays match in their indexes (i.e. v0=vt0=vn0, v1=vt1=vn1, v2=vt2=vn2), I can efficiently draw them like so:

      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_NORMAL_ARRAY);
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);

      glVertexPointer(3, GL_FLOAT, 0, vertex_array);
      glNormalPointer(GL_FLOAT, 0, normal_array);
      glTexCoordPointer(2, GL_FLOAT, 0, texture_array);

      glDrawElements(GL_TRIANGLES, vert_and_norm_size, GL_UNSIGNED_BYTE, index_array);
      
      glDisableClientState(GL_TEXTURE_COORD_ARRAY);
      glDisableClientState(GL_NORMAL_ARRAY);
      glDisableClientState(GL_VERTEX_ARRAY);
But my Object file only has the vertex array and vertex normal array matching in their indexes, and the texture coord array has different indexes: f 1/55/1 381/56/381 2/49/2 f 2/49/2 4/51/4 1/55/1 So the above code snippet won't work because "index_array"'s indexes won't match for the texture array. So my question is this: How can I best render my object when the indexes of my arrays aren't the same? Is there a methodology in opengl that I can have multiple index arrays, one for my vertex array, normal array, and texture array? Or something completely different altogether?
Advertisement
Not yet, but it'll be possible soon.
D3D10 already exposes functionality for per-attribute index arrays (although I cannot say more on performance), it's just a matter of time before it's available on GL as well.

For the time being, replicating the vertices is the only solution.

Previously "Krohm"

This topic is closed to new replies.

Advertisement