Non-square, non-power-of-two textures

Started by Jens v.P., December 10, 2007, 18:07:21

Previous topic - Next topic

Jens v.P.

The question was discussed sometimes before, but I'm still not sure how it works...
(Besides, the topic linked to in http://lwjgl.org/forum/index.php?topic=1657.0 is not found).

So, again:

Is it possible to use non-square and/or non-power-of-two textures? Of course, any image can be scaled and the tex coordinates can be set accordingly. But since I have to use a lot of different textures, I'm wondering whether it is possible to use other textures directly (to save memory).
Do I have to enable some extension?
Currently I'm able to load a texture (from an SWT image). The image has to be square and its width a power of two. What to I have to do to get rid of these constraints? Is there an example available?


Orangy Tang

Non-square but still po2 textures (eg. 32x128) should work fine everywhere without any extensions. You have to go really far back (ie. voodoo 2) to find any cards which don't support this.

For non-po2, then you need either ARB_texture_non_power_of_two or EXT_texture_rectangle. From memory, the ARB one is newer and generally better - basically non-po2 textures work just like regular ones. Mipmapping, tex coords and clamp modes work just as before. Basically just check for the presense of the extension (and/or Gl2.0) and load in your textures as before.

The ext extension is older and pretty limited - no mipmaps, and texture coords are specified as pixel coords (ugh) instead of normalised coords. IIRC  texture clamping is different too. You need to use some new tokens when creating your textures I think to actually use this extension.

Jens v.P.

I've got a MacBook Pro, and glxinfo prints out all the necessary extensions: GL_ARB_texture_non_power_of_two, GL_EXT_texture_rectangle, and GL_ARB_texture_rectangle.

But it seems as if it is not that simple. Using non-po2 textures is working, but non-square isn't. If a texture is a non-po2, GL_UNPACK_ALIGNMENT must be taken into account (on a Windows XP system, unpack alignment is 1 so this doesn't matter there, on my system it is 4).
A non-square texture isn't working -- I still haven't figured out how to use it. Simply "using" non-square textures doesn't work. Something is displayed, and I can recognize that it "should" be my texture, but I don't know how to correct it.