Jump to content
  • Advertisement
Sign in to follow this  
RokkumanXRX

Sprites at a power of two.

This topic is 4584 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've got a -hopefully- small question. I've just been introduced to the fact that all sprites must be at a power of two, however, there have obviously been many tricks used in order to get around having a game full of sprites of equal proportions. What's an effective way to acheiving this? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Sprites don't have to be powers of two, only textures do. So what you can do is shrink/enlarge the quad/traingle that the texture is on to get different size sprites. And you can show only part of a texture on a quad/triangle. And if you're just using something like SDL for graphics, then you don't have to worry about this at all.

Share this post


Link to post
Share on other sites
Right. For OpenGL at least, you can pack as many sprites onto a texture as possible and just use the area of the texture you need. OpenGL (and DX too i believe) need the raw texture to be a power of two for the hardware to use effectively. But that says nothing of sprites.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks for taking the time to reply. I'm folliwng this tutorial: http://gpwiki.org/index.php/SDL:Tutorials:Using_SDL_with_OpenGL , and I might be misunderstanding something... according to the tutorial, doesn't the glory of using OpenGL for sprites come from the fact that you're actually texturing a flat 3D surface made to act 2D, so that you can rotate it, scale it, and all that nice stuff? Or is there a way to still achieve this through using SDL for drawing while OpenGL is merged?

Share this post


Link to post
Share on other sites
You are correct.

If you use SDL+OpenGL, you are using OpenGL exclusively for drawing. SDL is used for input, windowing, and "miscellanea". One of those things is graphics loading. Basically, you can use SDL_img to load a graphic file (power-of-two texture) into an SDL surface, then convert the SDL surface into an OpenGL texture proper. You then dump the SDL surface, as it is just a temporary.

Once you have the OpenGL texture packed with your sprites on it, you can just draw a quad textured with the OpenGL texture and clamped to the appropriate coordinates of sprite on that texture. What you are effectively doing is "drawing" a subsection of the texture so that it looks like a sprite on the screen. Since it's just a textured quad, you can also rotate, scale, flip, blend, color, deform, and otherwise mutilate it. You can't do that with just SDL graphics. Yeah, OpenGL!

Share this post


Link to post
Share on other sites
but it IS actually possible to load non-power-of-two textures in openGL.
one method mentioned above is to put your sprites on a pot-texture (pow of 2)
but you can also use GL_ARB_Texture_rectangle to load NPOT-textures.
Or you can use gluScalef (or gluBuild2DMipMaps, wich use gluScalef) to strech your NPOT to a POT texture.


edit:
in openGL2.0 the restrictions of POTs are totaly removed.
they implementet the GL_ARB_Texture_rectangle-extension in OGL

Share this post


Link to post
Share on other sites
Quote:
Original post by WarMuuh
but it IS actually possible to load non-power-of-two textures in openGL.
one method mentioned above is to put your sprites on a pot-texture (pow of 2)
but you can also use GL_ARB_Texture_rectangle to load NPOT-textures.
Or you can use gluScalef (or gluBuild2DMipMaps, wich use gluScalef) to strech your NPOT to a POT texture.


edit:
in openGL2.0 the restrictions of POTs are totaly removed.
they implementet the GL_ARB_Texture_rectangle-extension in OGL
Just a little clarification on this...

The image scaling function you are thinking of is gluScaleImage.

You can indeed use GL_ARB_texture_rectangle to use non-power-of-two (NPOT) textures in OpenGL. There are some restrictions and differences to it than normal textures however such as no mipmapping, limited wrap modes, and non-normalized texture coordinates.

It's true that in OpenGL 2.0 the NPOT texture restriction is gone, but it's not because of GL_ARB_texture_rectangle. It's because GL_ARB_texture_non_power_of_two has been promoted to core OpenGL. GL_ARB_texture_non_power_of_two allows you to use NPOT textures in EXACTLY the same way as POT textures, so it supports mipmapping, all wrap modes, and uses normalized texture coordinates. For the time being at least, it does seem like most implementations are not as efficient with NPOT textures as they are with POT textures so it is still recommended to use POT textures where you can.

Share this post


Link to post
Share on other sites
Interesting. I was actually creating a new texture for every frame of a sprite. Is that worse than specifying clamp coordinates to one texture?

Oh, and how do you use GL_ARB_texture_non_power_of_two ?

Share this post


Link to post
Share on other sites
You can use a different texture for each sprite, but if your sprite is not the full size of the texture, you are wasting video memory.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!