glDrawArrays vs glDrawElements

here’s the deal: I’m drawing a mesh 2020=400 quads total. To improve performance I choosed to use triangles and vertex arrays, so my vertex array is 4006=2400 (6 because 2 triangles in a square). This is what I do:

GLfloat mesh[4200][3];
//fill up array
glVertexPointer(3, GL_FLOAT, 0, mesh);
glDrawArrays(GL_TRIANGLES,0,2400);

How can I use glDrawElements, is it faster? What’s the diference?

From my understanding I don’t think you’d get any performance increase by using glDrawElements. I think it does the same thing as glDrawArrays just in a different input format.

I do have a few related questions though.

How come glDrawElements only alows types of GL_UNSIGNED_INT, GL_UNSIGNED_SHORT, and GL_UNSIGNED_INT? What if I’m using floats?

Also using glDrawElements or glDrawArrays I have the following problem:

  • I have to draw my polygons in a particular order for transparency reasons
  • Using this order my texture for each polygon switches almost every time
    So is there a way to sort of call a glBind automatically depending on which element in my array I’m at. (I bet there isn’t but opengl has supprised me before.)

wow, you read my mind!!!
I don’t know how can I use a glBind inside a glDrawArrays or glDrawElements. If you get something concerning this matter let me know…

Nope, glDrawElements will not magically do a glBind for you. For transparent sorted polygons you must call glBind every time a new texture is needed. From my experience, a call to glBind is not needed for every transparent polygon. Typically, transparent polygons that are close to one another, also use the same texture. So I group my triangles after sorting them. And then you have to consider, how many transparent polygons are there in a typical scene? For example, in a Quake 3 map, there usually is not that many in any given scene. In fact most of the transparent polygons are temporary entities, and their variety is usually quite limited. One thing you might try with the smaller textures used with transparent polys is to tile them into a single texture and load that into OpenGL, and then use the texture coordinates cleverly to use the tile you need. This approach works very nicely for particle systems with key framed animation. Imagine a particle system of glowing, globuals, flickering with fire as they fly up into the air, and then change to into red glowing beads as they fall down, finally vanishing after a short period of time. Believe me, it is beautiful. And it is all done using just one 256x256 texture (and a lot of polys).

that’s all right folks, but it still doesn’t aswer my question: how to use glDrawElements with the problem above?

Regarding your question KRONOS, I think you would gain more speed by using an array of triangle strips. In fact glDrawElements should be a little slower than glDrawArrays since the former uses an index array to determine which element to draw where as with the latter, no such indexing is used.

yes, I know that but then how would I pass from one line to the next (keeping the front face correct) without another call to glDrawElements ?