Animated Sprites


I just started to developon iPhone, so I’m discovering OpenGL:)

I want to create animated sprites using glTexImage2D.
What’s the best way for this purpose ?

  • use glTexSubImage2D ?
  • create an array of textures ?

By the way, where can I find an code sample demonstrating how to use glTexSubImage2D ?


Ideally you should use a single texture that contains all animation frames for the sprite(s). E.g. if you have 16 animation frames for a 32x32 sprite, arrange them side-by-side in a 512x32 texture. When you want to animate the sprite simply set the texture coordinates to select the right subrectangle from the texture. Also if you have several animated sprites try to place as many of them as possible in the same texture so you can draw all of them with a single draw call.

Using glTexSubImage2D is thus the good idea ?
Or there is another way to set the texture coordinates ?

glTexSubImage2D updates the texture image data itself, not the coordinates. And using it may be slow. In general you should upload all image data needed in the foreseeable future at initialisation time, e.g. level load time.

You set the texture coordinates with glTexCoordPointer.

I finally managed to draw my animated textures, thanks for your answers.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.