texture sizes other than powers of 2???

Started by
18 comments, last by BriTeg 21 years, 5 months ago
In Nehe''s lesson #6, it says "...there are a few VERY important things you need to know about the images you plan to use as textures. The image height and width MUST be a power of 2. The width and height must be at least 64 pixels, and for compatability reasons, shouldn''t be more than 256 pixels. If the image you want to use is not 64, 128 or 256 pixels on the width or height, resize it in an art program. There are ways around this limitation, but for now we''ll just stick to standard texture sizes." What are the "ways around this limitation"? I would like to support texture sizes other than powers of 2, and also wider than 256. Does anyone know how this would be done, or know of any links that explain what to do? Thanks, Brian
Brianmiserere nostri Domine miserere nostri
Advertisement
well if the texture is bigger then 256 you can make 2 or more out of it and set them acrose quads (need to draw more polys this way). but theres no way around the <64 pixel one

hope that helps

-Ian
-VBLimitsSorry about the Spelling..
I am writing a tool that let''s end users supply bitmaps to be used as textures. Suppose the bitmap they want to use is 297x451. Is it possible to make a texture of these dimensions? Just considering the width, two textures (256 and 64) = 320 which is too much, and apparently I can''t go smaller than 64 for the second texture. But I don''t even want a second texture anyway! Is there no way to have textures with odd widths like this? I suppose I could resize the bitmaps in code, but I risk loosing image quality if I have to shrink everything down to 256. Any ideas?
Brianmiserere nostri Domine miserere nostri
quote:Original post by BriTeg
... and apparently I can''t go smaller than 64 for the second texture...


Actually, the minimum texture size is 1x1. An implementation must support texture sizes up to at least 64x64, maybe you misread something.

---
Visit Da Shovvkejs.
---Mikael Lax
There is no lower limit on texture size. The statement that it must be greater then 64 is incorrect.
To get a strange sized image into a texture, you could scale it so it is a power of 2 (gluScaleImage will do it), or you could look into the NV_texture_rectangle extension.
Also, almost all modern cards support textures larger than 256. For example, even a TNT supports up to 1024x1024.

http://users.ox.ac.uk/~univ1234
Thanks for the replies! They help.

Is there any way to determine at runtime the maximum texture sizes a video card supports?
Brianmiserere nostri Domine miserere nostri
quote:Original post by BriTeg
Is there any way to determine at runtime the maximum texture sizes a video card supports?

glGet with GL_MAX_TEXTURE_SIZE.

I think the workaround NeHe meant is using mipmaps. That way OGL will resize all the texturen into correct ^2 format without qualityloss (AFAIK).


Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][E-mail]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

SMALL TEXTURES
That''s right that you can use textures lower than 64. Though if your texture is really small, say 2x2, you may need to call glPixelStore for proper data alignment.


BIG TEXTURES
Of course you can use texture higher than 256, but that depends on the card''s limitations obviously. If you have a 256x256 texture, and if the card does not support textures higher than 128x128, I''m afraid the only solution is to shrink the picture to fit hardware requirements.

I do not recommend to get the maximum available texture size with GL_MAX_TEXTURE_SIZE. This is depreceated and you''d rather use glTexImage2D with GL_PROXY_TEXTURE_2D.


NON POWER-OF-TWO TEXTURES
And finally, YES you can use non-power-of-two textures. This has the very annoying, yet not deadly, disadvantage to forbid texture repetition. The trick is very simple : create a bigger texture (power-of-two sized) and fill partially the texture with the non-power-of-two picture.

For example with your 297x451 bitmap : first call glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL) to allocate memory for the 512x512 texels, and then fill a part of it with your bitmap thanks to glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 297, 451, GL_RGB, GL_UNSIGNED_BYTE, bimap_pixels).
(note: the later function is available since OpenGL1.1, just like glBindTexture).

The problem with repetition is pretty obvious I think.

Remember that you may not fill your texture with gluBuild2DMipmaps because this function will try to resize the texture to its closest power-of-two size (thus losing quality). That also means that you have to perform your own mipmaps if you want them. Also note that mipmapping may show seams. If you already know how to take care of seams with borders, the solution is the same.
Alternatively, you could stretch the irregular texture across the power-of-two one, so you can repeat it.

~CGameProgrammer( );
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.

This topic is closed to new replies.

Advertisement