We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › glDrawElements() and non-parallel data arrays
Page Index Toggle Pages: 1
glDrawElements() and non-parallel data arrays (Read 503 times)
glDrawElements() and non-parallel data arrays
Apr 23rd, 2008, 10:13pm
 
I'm trying to use glDrawElements() to draw geometry from an obj file. I've created separate arrays for vertex,normal and texture coords and have a index array. The problem i'm running into is that a typical obj file has separate indexes for each data type. Opengl on the other hand only uses one index to traverse all three arrays. In order for glDrawElements() to work these separate arrays must be parallel to each other. so a line for a Quad face in a .obj file that reads:

f 1/1/1 2/2/2 3/3/3 4/4/4

is fine. but a line that reads:

f 7/8/13 9/12/14 10/11/15 8/8/16

won't work since the data isn't parallel.  if opengl only uses one index to traverse the three arrays then the size of the three arrays has to match also.  for example if i'm drawing a simple cube using an indexed array:

Total number of vertices = 8
Total number of normals = 24
Total number of Texture coord = 14

after reorganizing the data so that the three arrays match in size and order the number of vertices goes from 8 to 24, not a big deal for a cube but if i'm dealing with 500,000 polys... well you get the idea. why even bother using an indexed array?
Re: glDrawElements() and non-parallel data arrays
Reply #1 - Apr 25th, 2008, 3:01am
 
i haven't implemented this myself but i had a quick read of my new-smelling opengl book, so i could be way off...

theres another method

glMultiDrawElements()

which allows you to pass in an array for count, so you can specify the exact length of each array.

like i said, i could be way off.
Page Index Toggle Pages: 1