i have problems with this function. It’s about other data like normals and texturecoords.

I have cube. it has 8 vertex positions. 36 normal positions and 12 texcoord positions.

How can i draw it with glDrawElements ? because vertices, normals aren’t same, how indices works there ? How to sort normals and textures to get it work ?

i was looking for examples on internet, but lots fo them aren’t using normals.

Thank you for answer

Triplicate the number of vertices. This is the only way, if you want to use glDrawElements and draw a regular cube. The index-array is a unique array for all vertex/normal/texture-data. So, you need 36 instances of vertices, texture coordinates and normals.

Aleksandar: but if i triplicate number of vertices, It’s same as DrawArrays, isn’t it ?

Unfortunately, YES!

The cube is very inconvenient figure for a glDrawElements() call. glDrawArrays() is worse choice in most cases, because it requires to duplicate vertices as many times as they appear in the drawing scheme. For example, if you have a tessellated surface, almost all vertices must be repeated four (or more) times, nevertheless the noramls and texture coordinates are the same. Using glDrawElements() would be more than 3 times better solution (not 4x, because you need additional index array).

If you subdivide each side of the cube, for any reason, than glDrawElements() would be (again) a better solution, but you have to draw the cube as 6 separate tessellated planes.

This was discussed in other terms here too:…6265#Post266265

and here: