Sign in to follow this  
Vero

OpenGL 2d animation: best practices?

Recommended Posts

So, I've come to the point in my game were I feel I need to come past this hurtle before I move on to more complex features. I'm more or a programmer than an artist but I'm learning a few techniques for pixel/ 8bit style art. (btw what's your recommended program for making art? I'm mostly fiddling with it in MSpaint right now)

anyway here's run down of questions I have.

Whats the best way to creating a sprite in openGL, right now I would simply load a series of textures and when moving as time passes the textures would be rotated over the GL_QUAD to look like walking, Is there a better/ cleaner way to implement this in a 2d environment?

How would I go about creating transparency on parts of the texture? I've tried to implement a few examples of Masking but so far I haven't had any success, would I need to use something other than .bmps for this, e.g. .png

Thanks for any advice you can offer.

Share this post


Link to post
Share on other sites
[quote name='Vero' timestamp='1343319832' post='4963353']
Whats the best way to creating a sprite in openGL, right now I would simply load a series of textures and when moving as time passes the textures would be rotated over the GL_QUAD to look like walking, Is there a better/ cleaner way to implement this in a 2d environment?
[/quote]
Most 2D game engines use texture atlas (google it if you don't know it). The basic idea is to create one big texture containing all the sprites (enemy anims, player anims, projectiles, ...) and then use uv coordinates to map regions to the quads. The big advantage is you have to bind the texture only once for all the sprites which is a huge performance gain.

Actually this is more less like your idea of rotation the texture.

[quote name='Vero' timestamp='1343319832' post='4963353']
How would I go about creating transparency on parts of the texture? I've tried to implement a few examples of Masking but so far I haven't had any success, would I need to use something other than .bmps for this, e.g. .png
[/quote]

Yes simply use the alpha component of PNGs.

Good luck with your game! Edited by Dir3kt

Share this post


Link to post
Share on other sites
You can do as you say, "load a series of textures and when moving as time passes the textures would be rotated over the GL_QUAD to look like walking."

But it's more expensive than just loading one texture, a [url="http://opengameart.org/sites/default/files/tux_from_linux.png"]spritesheet/texture map[/url], and modifying the texture coordinates as time passes to point to different parts of the texture. This solution is a little more difficult to implement though, and your first solution will work fine and be performant enough as long as you don't have too many things being animated at once.


Either way, you'll also probably want some way of "defining" animations outside of the code. Historically, I've used both XML and Lua for this.

Share this post


Link to post
Share on other sites
You're going to want to avoid using a bunch of textures because binding textures is an expensive operation in OpenGL. Try arranging your sprites on a set of textures in a way that you minimize the need to switch between them.

[url="http://lazyfoo.net/tutorials/OpenGL/10_color_keying_and_blending/index.php"]Transparency with 2D textures[/url] is easy, just enable blending and set your transparency function with glBlendFunc().

Share this post


Link to post
Share on other sites
(This is slightly off topic from your question, but it relates)

just for some specifics on animation, I am not keen on OpenGL (getting there), but I have drawn sprites, I used this technique, I made 8 images for each direction (except only 1 for left and right since it can be flipped), each one I assumed was at a 4 pixel pace (aka 4 pixel movement between each frame) so this is how it worked in code:

pseudo code:
while moving right
move 4 pixel
go to next frame

otherwise if you were to simply animate it separate of movement you will get floating foot syndrome, where they look like they are doing a moon walk forward or something.

of course the more frames you have the better it will look, so once you get a sprite system, you will have a nice method of animation, that looks like the steps they are taking are moving them.

As for the program to use, MSPaint is fine, albeit limited, and it depends how 8bit you want to go, if you want to look like a nintendo game, mspaint is great, you can use photoshop if you want more tools and layers, you simply have to limit the pallet to 8 bit colors. Edited by Krum110487

Share this post


Link to post
Share on other sites
This article will help you get started with the sprites:
[url="http://www.gamedev.net/page/resources/_/technical/opengl/rendering-efficient-2d-sprites-in-opengl-using-r2429"]http://www.gamedev.net/page/resources/_/technical/opengl/rendering-efficient-2d-sprites-in-opengl-using-r2429[/url]

You will find this series of tutorials very helpful:
[url="http://www.codeproject.com/Articles/27219/TetroGL-An-OpenGL-Game-Tutorial-in-C-for-Win32-Pla"]http://www.codeproject.com/Articles/27219/TetroGL-An-OpenGL-Game-Tutorial-in-C-for-Win32-Pla[/url]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this