PDA

View Full Version : glDrawElements



wh1sp3rik
11-01-2009, 02:49 AM
Hello,
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

Aleksandar
11-01-2009, 05:01 AM
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.

wh1sp3rik
11-01-2009, 05:53 AM
Aleksandar: but if i triplicate number of vertices, It's same as DrawArrays, isn't it ?

Aleksandar
11-01-2009, 07:06 AM
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.

overlay
11-01-2009, 01:51 PM
This was discussed in other terms here too:
http://www.opengl.org/discussion_boards/...6265#Post266265 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Main=51537&Number=2662 65#Post266265)

and here:
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=265744#Post2657 44