I started with OpenGL ES 2.0 about two weeks ago. In the beginning using Vertexarrays seemed fine but now that I want to load .obj files I need to work with an indexed system.
I got the vertex- and indexbuffer code from an OpenGL ES starter book.
I tried to draw a square and everything works perfectly. Then I tried to add texture coordinates to my vertexdata the same way I did before with the vertexarray. The texture on the square only consists of weird lines and I have no idea why.
Both ways use the same basic texture shader and both can draw the vertices.
The error I get says: A vertex attribute index out of boundary is detected.
Note that OBJ’s indexing isn’t the same as OpenGL’s. The two major differences are:
An OBJ vertex has separate indices for position, normal and texture coordinates. An OpenGL vertex has a single index.
OBJ indices are one-based, OpenGL indices are zero-based (as are array indices in most modern programming languages).
So when you load an OBJ file, first you need to iterate over the list of faces and create a table of every distinct combination of position/normal/texture coordinate indices. Typically you have an associative array (e.g. std::map or std::unordered_map in C++) which maps a tuple of OBJ indices to a single OpenGL index, and an array (e.g. std::vector in C++) which holds the reverse mapping. Once you have that data, you use the forward mapping (associative array) to transform the list of faces (for each face vertex, map its tuple of OBJ indices to the corresponding OpenGL index) and the reverse mapping to generate the OpenGL attribute arrays from the OBJ arrays (which will typically be different sizes).
That’s what I’d expect if you tried to use the OBJ attribute arrays and indices as-is.
I don’t think that there should be any form of limitation considering that you should be able to ‘stack’ vertex coordinates, texture coordinates, normals, etc.
If I missunderstood you, please feel free to correct me.
hm … test out the glDrawElements(…). The elements-count might not be the number you figure. Using, thinking and talking about indices is sometimes surprisingly confusing.