Archived

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

How to store frame animations?

This topic is 5180 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''m building a primitive 2D engine based on textured quads. Currently it''ll load a texture from a file, map it onto a quad and the draw it wherever I like on the screen. For this purpose I''m using D3DXCreateTextureFromFileEx(...) to load the texture. Now I am attempting to add animations. My first decision was how animations should be stored. I settled on having a series of frames in a single bmp file and then specifying in the code when I load the texture how many frames there are and the size of each so that my program can parse it. So now I''ve loaded my texture using D3DXCreateTextureFromFileEx(...), but now I want to slice it up and copy each frame into it''s own new texture. Unfortunately I cannot find any functions in directX that can do this, is my approach doomed? 2 solutions that I''ve thought of: 1) Just keep the one big texture in memory and pass around coordinates to a particular frame instead of a seperate texture. I don''t think this is particularily elegent and would force me to rewrite a fair bit of code. 2) Store every single frame in a different file. This would be insanly messy. I guess I just refuse to accept that there is no way to slice up a texture once it''s in memory. Surely there is something I can do? Also, how do the pros store animations? Are there any software packages to assist in creating 2D animations?

Share this post


Link to post
Share on other sites
I'm not aware of any functions for splitting textures in DX (there might be some, though). A little hack you could do, however, is draw a quad with the coordinates for the first frame and render it to a texture, then do the same with the second frame, etc. Then delete the original texture.

My Website | Everything you need to know about 3D Graphics | Google Search Engine

[edited by - Luke Philpot on October 12, 2003 6:22:22 AM]

Share this post


Link to post
Share on other sites
Its possible to to do but it defies the whole point of putting all the frames in one file to start with. Just adjust the texture coodinates in the texture according to which frame you want to render.

Share this post


Link to post
Share on other sites
Generally what the "pros" do is have 1 large texture with all the individual frames on that texture, and then specify the UV coordinates in some sort of tool.

If you really really want to do it the "splitting" way like you mentioned, then you could do it, it would just be a hassle to code and not very efficient. To do it in DirectX, basically what you need is your original texture, and the UV coordinates for each frame. Then what you do is you loop over each frame, determine the dimensions (width/height in pixels) given the UV coordinates for the upper-left and lower-right corners, then round that up to the nearest power of 2, and call CreateTexture to create a new texture... Then you lock that texture and copy in the region you want from the original texture, and probably stretch the frame to occupy the entire destination texture, using linear filtering ideally. (This is what the D3DXLoadTextureFromFileEx function does, iirc).

I don't know of any popular packages for creating 2d animations, and this probably is somewhat coupled to your implementation anyways. It's not too hard to roll your own tool, if you think this is something that will be re-used a lot.

I can tell you how my animation tool works in case that might help...

First you create a texture sheet by picking all the images you want to be put into it. It automatically generates all the texture coordinates:


Then you create an animation by picking all the frames from the texture sheet:


The animation file itself is pretty small since all it contains is a reference to the texture sheet (a 32-bit value), then a few parameters like rotation, scaling etc... And then, a list of frames, which are just UV coordinates.

Hope that helps

Raj

[edited by - Rajansky on October 12, 2003 7:48:32 AM]

[edited by - Rajansky on October 12, 2003 7:49:31 AM]

Share this post


Link to post
Share on other sites