views:

150

answers:

3

Sorry if my question is uncleared. Let me elaborate.

I have a rectangle of size 100 x 200, and I have a graphic size 100 x 200 which fits with the rectangle. Since OpenGL requires all textures to have 2^n width and height, I basically put the 100 x 200 graphic right into a 128 x 256 image for this. It works fine for OpenGL because I simply requested it to draw only a portion of the texture that I need on the rectangle. However, what nags me is that in the 128 x 256 texture, there are a lot of unused spaces.

Is there a better way to deal with these unused spaces in this case? Or is this supposed to be the way to go?

+5  A: 

Pack multiple textures into one "sheet".

Jim Buck
Although I've seen some games use that method, it does make a programmer's life a little bit more complicated.
unknownthreat
If you're googling for the technique, it's sometimes called a Texture Atlas.
kibibu
A: 

Resize your image to fit better. You don't get anything for nothing in this world.

Henry
+1  A: 

If you must reduce padding to save memory you could split the image into multiple pow2 textures, e.g. split 100 pixels horizontally into 64, 32, 4 and 200 pixels vertically into 128, 64, 8. You'll also need to split the rectangle you're texturing into multiple corresponding rectangles (quads).

In this example you will be rendering 9 quads/textures instead of 1 so you will need to measure if there is a performance hit in your application.

You won't be able to use this technique if you're using bilinear interpolation as you'd require a texture border which I don't think is supported by OpenGL ES.

shouston