Jump to content
  • Advertisement
Sign in to follow this  
Tolito

OpenGL Sprite Sheet

This topic is 1996 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 have decided to go with OpenGL rendering for a project of mine that was originally using SDL. It is still using SDL, but it is going to be depending on OpenGL for some graphical operations. One of my sprite sheets happens to have the dimensions, 1892x66. Here are my questions:

  1. Are the dimensions all wrong for an OpenGL texture, considering the power-of-two rule? If so, what is the best thing I can do?
  2. Does storing a sprite sheet as a surface in SDL use less memory than storing it as an OpenGL texture?
  3. Am I better off using separate graphics in the sheet for left and right and using a surface in SDL than using OpenGL, given the dimensions? I wrote a function to copy a sprite from a sheet to a separate surface and mirrored the surface, but this was slow when called multiple times in one frame.
  4. Will someone please link me to a document or post some code that provides an example of this?

Thank you! smile.png

Share this post


Link to post
Share on other sites
Advertisement
  1. Non-power-of-two textures have been supported pretty much everywhere for ages. It might be a concern if you're running on > 10-year-old hardware, or some mobile platforms. That said, a power-of-two (or at least more square) texture might work better for mip-mapping, and for various hardware caches.
  2. All things (dimensions, bit-depth, etc) being equal, it should be no larger in a texture. Perhaps smaller if you use a compressed texture.
  3. In general you want to keep the number of separate draw calls to a minimum, and one of the ways to help do that is to keep related things in a single texture. But it sounds to me more like the problem you're experiencing is due to copying and mirroring multiple times--if you're probably going to use the mirrored image again, do it once and keep it in memory.

Share this post


Link to post
Share on other sites

Thank you for your response! You have earned yourself some more reputation!

 

Are dimensions ever too big, or should it work in OpenGL if SDL can load it as a surface?

 

Yes, the slowdown was due to how many times I was calling those functions. I was asking if the power-of-two rule and other problems that may arise relating to the use of OpenGL would be so much trouble that I would be better off sticking with SDL and including mirrored versions of sprites in the sprite sheets. I was including that little detail to serve as an explanation as to why I wanted to switch to OpenGL and how such a function was slow. Sorry for the confusion.

 

Do you happen to have any examples for what I want to accomplish? Thank you again!

Share this post


Link to post
Share on other sites

Don't have any examples, sorry.

 

The width ought to be fine, aside from my other comments. I think a minimum of 2048x2048 has been the standard since around GeForce 2, or around 15 years ago. Again, you might find some mobile platforms that don't support textures that large, I'm not terribly familiar with feature support on mobile platforms.

Share this post


Link to post
Share on other sites

IIRC there was also a requirement for texture sizes to be divisible by 4 (so width needs to be divisible by 4)

 

I couldnt find much information by googling, it might only apply to compressed textures.

Share this post


Link to post
Share on other sites

IIRC there was also a requirement for texture sizes to be divisible by 4 (so width needs to be divisible by 4)

 

I couldnt find much information by googling, it might only apply to compressed textures.

That is incorrect. The size can be any value, even compressed textures.

 

Compressed textures are commonly compressed in blocks of 4x4 pixels. If a block is not fully used, the data has to be padded to form a valid 4x4 data block, but the actual texture does not have to fill this block entirely.

 

You may be thinking of the byte alignment, which required the byte-width of the image to be a multiple of 4 bytes. But that was just a parameter you could set anyway and effectively disable by setting a 1-byte alignment,

Share this post


Link to post
Share on other sites

Thank you all for answering questions and providing useful information! Reputation for everyone! Have a great day!

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!