I’m dealing with OBJ file with OpenGL 2.1. This is OBJ spec: http://www.martinreddy.net/gfx/3d/OBJ.spec
According to that, a face is indicated as vertex/texture/normal where vertex, texture and normal are different, this mean index of vertex, texture coordinate and normal index in each buffers are different.
Question: How can i draw an object that supply different indicate buffers for each vertex, texture and normal arrays?
Sad answer, this is not possible in OpenGL. In OpenGL (and many other such systems, especially Direct3D), a vertex is conceptually the union of all the vertex attributes, like position, normal or texture coordinates (it’s unfortunate that the term vertex is often used only for the position attribute). So two vertices with the same position but different normal vectors are conceptually two different vertices.
That’s the reason, why you have to use the same vertex index for all attributes. So to draw an .OBJ file with OpenGL or similar libraries, you won’t get around processing the data after loading.
The easiest way is to completely drop indices and just store all vertex data for each triangle corner one after the other, using the indices read from the face specification, thus having
3*Fvertices and no indices. This, however is rather inefficient, since you probably still have many duplicate vertices, even if considering all attributes at a whole.Another option is to insert the index triples (comprised of vertex, texcoord and normal index) into a hash table and map it to a combined index. Whenever the index triple already exists, you replace it by the one index in the hash table and when it doesn’t exist, you add a new vertex (comprised of position, normal and texCoords) to your final rendered vertex arrays, indexing the file’s vertex arrays using the index triple (and insert this new vertex array size as unique index into the hash table, of course).