PDA

View Full Version : animated textures



CKulT
09-09-2004, 07:56 AM
hello. How can I show animated textures (like GIF) ?

09-09-2004, 08:50 AM
Provided you have properly decoded the image into main memory including all the frames, there are multiple ways you can go about making OpenGL display your animation.

Presently, I've found that using 3D textures makes a good animation system, provided you have a pow2 number of frames. Then you draw a quad where the r coordinate of each vertex is (float)currentframe/numframes and you will get the proper image. If you apply filtering to the texture, you will even get some interpolation effects for free from OpenGL.

You could also load each frame into one of the members of an array of textures, and change which one is bound and rendered in a specific spot dynamically at run time.

Finally, if you want to use the absolute minimum texture resources but don't mind a little client->server traffic every now and then you can create only one texture and just glTexImage2D the next frame into it every time it has to change.

dorbie
09-09-2004, 08:52 AM
As you render your scene, each frame use glTexImage2D or glTexSubImage2D to update the texture image to the desired animation frame. Alternatively store each gif frame as a unique texture and cycle through the texture handles in the bind call to update the animation.

The first approach will spend a lot of time sending data to texture memory. Probably not an onerous amount but MIP maps could be a problem. The second method will use more texture memory and can't run an open ended animation, however the animation would have absolutely no rendering performance overhead.

CKulT
09-09-2004, 01:12 PM
Thanks.