Advertisement

Padding an image

Started by July 02, 2004 12:46 AM
6 comments, last by _DarkWIng_ 20 years, 5 months ago
Hi guys Is there a way to automatically do padding on an input image so that I can get the dimension of the width and height to be in the power of 2? This is due to the restriction that OPENGL texture can only work in this way. I am not going for scaling because I need not repeat the texture and texture coordinates are already available to me. Thanks. Rgds
textures MUST be a power of 2.. 'Padding' a texutre will change the texture cord needed to address the texture correctly as 1.0f (on the X axis) is always going to be the right edge. padding effectivly moves the image in so the x cords needs to be scaled accordingly.

you are best off to ensire that all textures are multiple of 2's in the first place or if not, then scale them to the nearest power.. if you scale it then you won't have to change your texture cords..

what does scaling and repeating the texture got to do with each other ??
Advertisement
Quote: Original post by Jumpman
textures MUST be a power of 2.. 'Padding' a texutre will change the texture cord needed to address the texture correctly as 1.0f (on the X axis) is always going to be the right edge. padding effectivly moves the image in so the x cords needs to be scaled accordingly.

you are best off to ensire that all textures are multiple of 2's in the first place or if not, then scale them to the nearest power.. if you scale it then you won't have to change your texture cords..

what does scaling and repeating the texture got to do with each other ??


I thought if you scale the image to the nearest power of two, you have to re-adjust the texture coord as well since the texture information now covers a larger area. As for padding, no readjustment is not required since you will still be sampling from the same place and ignoring the padding region. Getting a little confused here.
For standard openGL texture coordinats for a texture are in [0..1] range. If they go out of that range then warp methods apply (repeat, clamp,...). It does not matter what size the texture is. I would say in your case to just resize textures (in engine or by some external tools like photoshop) to nearest POT and keep texture coordinats as they are.

If your card supports non-POT textures you can use them, but then you have to work under different rules. Personaly I would stay away from them for a while.

>>what does scaling and repeating the texture got to do with each other ??
If you use texture in just once corner of bigger texture, you can't repeat that portion. You can only repeat full texture.
You should never let your fears become the boundaries of your dreams.
Thanks for the explanation. So is there a way to do automatic padding in OPENGL? Currently I am using photoshop to do it.
Quote: Original post by Mystery
So is there a way to do automatic padding in OPENGL?

Not really. There is one GLU function that will load non-POT image and scale it up to next POT but I don't think it's very usefull. If you just want to pad it to next POT (and leave the rest of image black) then this is very simple to code. But if you want to scale it up then it can get a bit more difficult. Depends on what kind of resampling you wnat.
You should never let your fears become the boundaries of your dreams.
Advertisement
When using texture coordinates, the end result is the same whether the texture is 64x64 or 512x512. The coords work kind of like a percentage. (0.5 0.5) is at the center of the texture no matter what size the image file is. What is affected will be detail. A larger texture can hold better detail, but the texture coords are still the same. When using coords greater than 1 the texture repeats itself. So if instead of using (1, 1) you use (2, 2), you get the texture repeated four times, one in each corner. This is actually useful for walls that you want to keep a higher detail, if you have a tilable texture.


Quote: Original post by kburkhart84
When using coords greater than 1 the texture repeats itself. So if instead of using (1, 1) you use (2, 2), you get the texture repeated four times, one in each corner.

Not really. This works if you set texture warp to repeat. There are other very usefull modes also. Clicly#1, Clicky #2
You should never let your fears become the boundaries of your dreams.

This topic is closed to new replies.

Advertisement