views:

221

answers:

2

Word on the street is that glDrawElements is much faster then glDrawArrays.

So I want to display everything using glDrawElements. The problem I have is that I have a bunch of images I want to pop onto the screen. Each image is in a different texture.

Is it possible to use glDrawElements to do this?

How can I switch the texture

A: 

You can't, directly.

What you can do is make a texture atlas, by making one big texture containing all of your little textures, and then adjust your texture coordinates accordingly.

Also, where did you hear about the comparison between glDrawArrays and glDrawElements? I've never seen a convincing, all-cases-included comparison.

Jesse Beder
I got it from a video tutorial on a site called 71 squared. I guess for the iphone anyways... that making 3 gldrawarrays calls vs 1 gldrawelement calls was crazy slower due to the fact that the cpu is used and the iphone cpu couldn't keep up. Making the one call used graphics hardware acceleration to do the same thing.
Mel
A: 

Vertex indexing (i.e., glDrawElements) can greatly reduce the size of your vertex buffer if you often have vertices that are shared between multiple primitives.

For example, if you're drawing a mesh with GL_TRIANGLES, you'd definitely want to use indexing. If you're simply drawing a bunch of disjoint triangles, there's not much reason to use indexing.

Regardless of whether you use glDrawElements or glDrawArrays, it's always desirable to minimize the number of draw calls. Using a texture atlas allows you to combine multiple draw calls that would otherwise be separated with calls to glBindTexture.

prideout