PDA

View Full Version : best way to animate "2D" sprite...



architekt
02-11-2002, 11:17 AM
By 2D I just mean I'm using Z=0 for everything and an Orthographic projection.

Let's say I have an animation of a character walking on screen. One way I thought of how to do this is as follows:

Generate a display list for each frame of animation. In each display list is just a simple 2D rectangle, along with the appropriate texture coordinate settings along with a binding of the texture to the rectangle (using glBindTexture). When it's time to draw a new animation frame, simple update some index into that character's display list array and draw that display list instead.

OR,

perhaps use glTexSubImage2D....maybe have all the animation grahpics in one image and simply update an index into this "master" texture.

The bulk of my code consists of simple 2D blits (yes, yes, it's all 3D, but I'm just keeping Z at 0)...actually I think that is all that the rendering code consists of. Are there any specific tips if that's all that my rendering functions are doing?

Thanks for your help, I appreciate it.

Korval
02-11-2002, 02:07 PM
Having all those display lists may limit the amount of texture memory you have avaliable. Instead, just put the sprites in a few large textures and select appropriate texture coordinates from them.

Elixer
02-11-2002, 03:10 PM
I would have to agree with Korval, stick all your 'sprite animations' in 1 file, and then modify the tex coords to 'animate' them.

architekt
02-11-2002, 03:39 PM
I assume then that the following is what I should do instead:

set up just 1 display list in some init code just to set up a basic rectangle with the proper texture coordinates set.

In main rendering code, just before the rectangle display list is called, call glTexSubImage2D, and then call the rectangle's list.

My only concern is that it seems like now there's the extra overhead of a function call per game loop, and I'm not sure I see how I save on that much memory. I'd still need the same amount of memory in the larger bitmap as I would in the sum of each individual sprite frame. It seems to me that the only thing I save on is the memory taken up by the display lists themselves...which I'm not sure is significant for just a 4 vertex rectangle. I don't suppose anyone wants to enlighten me? Thanks =)

nexusone
02-12-2002, 05:23 AM
Is there a good example of doing that, I been loading each cell of the animated sprite as a texture.


Originally posted by Korval:
Having all those display lists may limit the amount of texture memory you have avaliable. Instead, just put the sprites in a few large textures and select appropriate texture coordinates from them.

zed
02-12-2002, 11:13 AM
i have to disagree with korval + Elixer. store each frame in a different texture ie whats the point of having a texture bound if youre only using a part of it that frame, this method will be quicker + wont suffer from the problems of edge bleeding (esp when u generate mipmaps)


texsubimage(..) is a bad idea also. best to load all textures at initiation time (unless maybe youre using 100's of textures)