Sprite Sheet

Started by
5 comments, last by Tolito 11 years, 2 months ago

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

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.

throw table_exception("(? ???)? ? ???");

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!

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.

throw table_exception("(? ???)? ? ???");

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.

o3o

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,

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

This topic is closed to new replies.

Advertisement