Archived

This topic is now archived and is closed to further replies.

Animation + Open GL?

This topic is 5311 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering say I have one bitmap filled with a series of pictures like sprites and the picture changes like for walking attacking ect. Is there some way to use this and display it frame by frame on a plane inside open gl? Does anyone know how to do this ? I dont really think it would be very memory saving to create tons and tons of textures.... I could do that but it would be quite a lot of files :/ [edited by - DevLiquidKnight on June 3, 2003 3:27:38 AM]

Share this post


Link to post
Share on other sites
why shouldn t that be possible

you pass the pointer to the top left pixel of the sprite texture you want
and specify the width and height

ogl knows how to handle this

you can also create one huge texture
with wrappingmode "clamp to edge"(i think)

and pass uv coordinates between 0 and 1

lets say you have a sprites 128*128
you have 16 sprites
that means one is 32*32

so you pass 0, 32/128 ..... so wheres the problem

Share this post


Link to post
Share on other sites
create each sprite within the bmp file, and also a state variable somewhere in your code that tracks which sprite should be displayed on the current frame.

for example:
you could use a 256x256 bitmap with 8 32x32 sprites arranged in a row, so that glTexCoord2f()''s arguments could be a function of a state variable.

all you have to do is cycle through the state variable, and you''ll have animation.




Share this post


Link to post
Share on other sites
A similar technique is often used to render text. This is probably a great place to use a display list when you're looking to optimize your code a little.

If you have a source texture of width a, and every sprite is of width b, then the nth image can be identified with the horizontal texture coordinates given by s1=nb/a to s2=(n+1)b/a.

So, if your source texture has a width of 256 pixels, and every sprite has a width of 32 pixels, your low horizontal texture coordinate for the third image is (2)32/256=0.25 to (3)32/256=0.375. Note that you count the image from zero, not one.

Similar logic follows for the vertical texture coordinates. Sprites that span multiple rows can be handled through use of the modulus operator.

"Last time, I asked: 'What does mathematics mean to you?' And some people answered: 'The manipulation of numbers, the manipulation of structures.' And if I had asked what music means to you, would you have answered: 'The manipulation of notes?'" - S. Lang

[edited by - Zorodius on June 3, 2003 5:16:02 AM]

Share this post


Link to post
Share on other sites