Animation with Mipmaps

Started by
7 comments, last by GenuineXP 17 years, 7 months ago
Hello. I'm working on a basic game engine that uses OpenGL to render 2D graphics. I was wondering if it's possible to produce animations on quads in OpenGL using mipmaps. Could each frame be loaded into a different level mipmap all of the same dimensions? Basically, I'm wondering if I can store an animtation in a single texture's mipmaps so that I can address that texture with one texture name (GLuint) and access each frame of the animation by specifying a mipmap level to use. At this point, my engine supports two animation processes through subclasses of the class Sequence: Strips and Layers. Strip objects create animations by using one large texture with each frame distributed evenly in rows. With this method, the target texture is always the same but the texture coordinates differ. Layer objects create animations by loading many small textures, each individual texture being a frame in the animation. The texture coordinates in this method never differ, but the target texture does. So, would it be possible to add some sort of mipmap animation? I'm using DevIL to load my images and it natively supports loading GIF files with mulitple frames. In fact, DevIL stores each frame in a similar way to mipmaps. Thanks!
Advertisement
A mipmap level must be half the size of the previous level. Sure you can use it for animation, as long as you're fine with the size requirement. Although it would be way easier to use a 3D texture instead, or subtexture a 2D one, if you really need to put it all in one single texture object.
Thanks for the reply. I'm unfamiliar with 3D textures in OpenGL. I assume they're just texture with any number of "layers" or "depths". Can anyone give me any good references I can learn about 3D textures from?

Thanks again. I appreciate it.
I've looked up 3D textures in OpenGL and they seem pretty easy to use (thanks, OpenGL!). But... I'm not sure how to get the texel data I need in glTexImage3D() from DevIL.

Any clue as how to do this? Can I somehow add layers to a 3D texture after it's been loaded? I'm not sure how to squeeze all the data for several images into one pointer to pass to glTexImage3D().

Thanks again. :-)
Create the texture object with glTexImage3D as you want the final texture to be, but pass a null pointer for the image data. This allocates a textrure but with uninitialized data. Then use glTexSubImage3D to upload the slices.
Thanks for all of the replies, everyone. You've been very helpful. :-)

I've switched to 3D textures, but now I'm having a new problem. Whenever I load 32-bit images (images that have an alpha channel), I get nothing. The texture is completely blank and I wind up with white, blank quads on the screen!

Other images work; I've successfully loaded 24-bit JPEGs and BMPs, but as soon as I load a few 32-bit PNGs, nothing happens. Is there a reason for this? Can I support an alpha channel using 3D textures?

Thanks!
Unless you're using OpenGL 2.0 or later, did you check the size of the images? Powers of two, you know.
My Texture class has a MakeCompliant() method that makes sure that the width and height of images are both a power of two before they're loaded by OpenGL.
Haha, I just realized that the MakeCompliant() method was still trying to use 2D textures! It probably wasn't that the images I was loading had an alpha channel, but that their widths and heights weren't powers of two and were being resized and then loaded incorrectly.

I'll try tinkering with it and see what happens.

Thanks again for all of the help.

This topic is closed to new replies.

Advertisement