Animation + Open GL?

Started by
3 comments, last by DevLiquidKnight 20 years, 10 months ago
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]
Advertisement
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
http://www.8ung.at/basiror/theironcross.html
Ive never seen this have an example ? lol...
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.




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]
You don't need to vote for the "lesser of two evils"! Learn about Instant Runoff Voting, the simple cure for a broken democracy!

This topic is closed to new replies.

Advertisement