glMultiDrawElements for Collada-files?

Ok, I got this last issue with my Collada-loader before I can release all my source code for the “Duke Bean’Em” game I showed at JavaOne.

I used glDrawElements for drawing my models, but I’ve discovered that it doesn’t work very well when it comes to loading models where I have indices also for normals and texture coordinates (as is the case in my collada file, see attachment). I’m guessing glMultiDrawElements would do the trick, but I can’t find any good examples on how it works in JOGL.

…or am I way of track and is there another, better way of doing this? :slight_smile:

Thanks!

I looked at the gl spec and glMultiDraw*() doesn’t do what you guessed it did. Instead it just takes multiple lists of indices, and iterates over those indices, calling glDraw*() on them. Probably the question that you’re wanting to ask is, is it possible to specify different indices for the different types of data associated with a coordinate(ie vertex, normal, tc, or fog coordinate)? I would very much like to know if there is a way of doing that because the solution that I have found is not very elegant. It requires looking at all of the coordinates(vertex,normal, and tc) and duplicating the ones that have the same vertex but other parts different and then modifying the index to access that new coordinate.

So it would mean that for a cube, each corner actually has 3 coordinates, since there are 3 different normals for each vertex. I don’t like that solution, however, since it can lead to a lot of extra data because of floating point error and if the mesh is faceted. So, anyone, is there a better way to do that?

In my experience the only thing to do is to replicate vertices where necessary so that the indices are the same for your coordinates, normals, texture coordinates, etc. Note however that you should definitely replicate as few vertices as possible.

Here’s a code snippet that gives the general idea.