3 index buffers

Posted by bobobobo on Stack Overflow See other posts from Stack Overflow or by bobobobo
Published on 2010-04-23T04:20:33Z Indexed on 2010/04/23 4:23 UTC
Read the original article Hit count: 369

Filed under:
|
|
|

So, in both D3D and OpenGL there's ability to draw from an index buffer.

The OBJ file format however does something weird. It specifies a bunch of vertices like:

v -21.499660 6.424470 4.069845
v -25.117170 6.418100 4.068025
v -21.663851 8.282170 4.069585
v -21.651890 6.420180 4.068675
v -25.128481 8.281520 4.069585

Then it specifies a bunch of normals like..

vn 0.196004 0.558984 0.805680
vn -0.009523 0.210194 -0.977613
vn -0.147787 0.380832 -0.912757
vn 0.822108 0.567581 0.044617
vn 0.597037 0.057507 -0.800150
vn 0.809312 -0.045432 0.585619

Then it specifies a bunch of tex coords like

vt 0.1225 0.5636
vt 0.6221 0.1111
vt 0.4865 0.8888
vt 0.2862 0.2586
vt 0.5865 0.2568
vt 0.1862 0.2166

THEN it specifies "faces" on the model like:

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

So, in trying to render this with vertex buffers,

In OpenGL I can use glVertexPointer, glNormalPointer and glTexCoordPointer to set pointers to each of the vertex, normal and texture coordinate arrays respectively.. but when it comes down to drawing with glDrawElements, I can only specify ONE set of indices, namely the indices it should use when visiting the vertices.

Ok, then what? I still have 3 sets of indices to visit.

In d3d its much the same - I can set up 3 streams: one for vertices, one for texcoords, and one for normals, but when it comes to using IDirect3DDevice9::DrawIndexedPrimitive, I can still only specify ONE index buffer, which will index into the vertices array.

So, is it possible to draw from vertex buffers using different index arrays for each of the vertex, texcoord, and normal buffers (EITHER d3d or opengl!)

© Stack Overflow or respective owner

Related posts about obj-file

Related posts about direct3d