Jump to content
  • Advertisement
Sign in to follow this  

OpenGL 2D animation in OpenGL

This topic is 4736 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

normally when doing 2D animation in SDL I would just use a rect to sort of crop the picture so that its the one I want however im not sure how to do this when textures are involved. would you generate each texture then just assign the current frames texture as the current texture to draw (which would most likely mean a diffrent picture per frame). I also thought about using the texture coorads as the sort of croping area but this would not alow for various texture sizes without implementing a diffrent draw method. The final problem I run into is having to use textures that are a ^2. Based on these problems do you think that I should be using textures on quads at all? should I just go for images instead? thanks for any help [smile]

Share this post

Link to post
Share on other sites
There's no reason you can't use the same method you use with SDL on OGL textures. The only difference is the quad/texcoord conversion, which (once you understand it) isn't too bad.

Assume you have a 256x256 texture which has 4 frame of animation:

(SDL: 128, 0)
(OGL: 0.5, 0)
(SDL: 0,0) +-------+-------+ (SDL: 256,0)
(OGL: 0,0) | | | (OGL: 1, 0)
| 1 | 2 |
| | |
(SDL: 0,128) +-------+-------+ (SDL: 256, 128)
(OGL: 0,0.5) | | | (OGL: 1, 0.5)
| 3 | 4 |
| | |
(SDL: 0,256) +-------+-------+ (SDL: 256, 256)
(OGL: 0,1) (SDL: 128,256) (OGL: 1, 1)
(OGL: 0.5, 1)

So instead of changing the src rect, you'll want to change the tex coords of the quad you're rendering the texture onto. And voila! You can use one texture to hold a whole animation (or more) of frames for your game.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!