Jump to content
  • Advertisement
Sign in to follow this  
othello

OpenGL Quick Question on Sprite Rendering

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

Hi, I'm working on a 2D renderer that draw sprites that can be animated. I'm currently implementing the system by storing each frame of an animation as a separate OpenGL texture. I did this because I was concerned that I might exceed the maximum texture size if I stored all the frames on one texture. My intention is that the system should be scalable. One thing I'm more concerned about is the speed. Although OpenGL renders 2D images blazingly fast, I still don't want to do something that is grossly inefficient. I am currently switching the bound texture for each frame of the animation. Would it be faster to store multiple frames in a texture and translate the texture coordinates? Also, is there a memory penalty I'm unaware of? I know that multiple high-res sprites with several frames of animation can quickly eat up video memory (especially without some sort of caching scheme). Does the video card pack textures in a certain way in video memory so that one method would be more efficient than the other? Thanks, -othello

Share this post


Link to post
Share on other sites
Advertisement
I'd recommend a single texture (within reason) containing all the sprite frames, then animate the UV coordinates to get to the frame you want. You could write a "sprite" boxing tool that would let you / artist / designer etc. select a box region (and therefore UV coordinates) of each sprite then it's easy to run through an animation of them without changing texture each frame.

Share this post


Link to post
Share on other sites
Thanks for the reply. So is changing the texture each animation frame expensive as opposed to changing the texture coordinates?

Share this post


Link to post
Share on other sites
I believe so yes, but check the documentation / google for sure.

As a rule of thumb - any state change when rendering is not good - eg the less things change the faster you can render. Not an easy task as you do have to change textures, meshes etc. but these can be batched to minimize state changes.

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!