LWJGL Forum

Programming => OpenGL => Topic started by: gimbal on August 28, 2005, 03:48:51

Title: question about a texture dimension problem
Post by: gimbal on August 28, 2005, 03:48:51
Okay, this is driving me nuts...

I am working on a pretty basic Quake 2 MD2 loader for the fun of it (porting it from some old C++ code I wrote actually). I have the model loader all setup and working nicely, up to a point.

I found a model on the net that has a 400*200 skin (that is actually used in a game). When I try to feed this texture to OpenGL, I get an error Invalid value (1281) (it is GL11.glTexImage2D() that is failing, I checked that with Util.checkGLError()).

Now seeing that either 400 or 200 is clearly not a power of two, I can understand that the code is failing... but how on earth would that model be loaded in Quake 2, which also uses OpenGL??? Is there some trick I'm missing?

Not that this is a big problem though, all other models that I've tried so far did have power of two dimensions for their skins. I was just wondering.
Title: question about a texture dimension problem
Post by: princec on August 28, 2005, 10:18:29
The texture image can either be:

1. Loaded using the NPo2 extension if it's available in which case you don't need to do anything

2. Stretched to fit into a Po2 texture

3. Put into the next smallest Po2 texture that fits and the texture coords adjusted

4. Packed into a big Po2 texture along with all the other little irregular textures and the texture coords adjusted

Cas :)
Title: question about a texture dimension problem
Post by: gimbal on August 28, 2005, 15:55:29
> 1. Loaded using the NPo2 extension if it's available in which case you don't need to do anything

Aha. I'll have to research that. Thanks for the info.
Title: question about a texture dimension problem
Post by: DustWorm2 on August 28, 2005, 17:32:43
If I understand your problem correctly.
To use non power of 2 texture use MipMap
// Mipmap texture
GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, 4, IL.ilGetInteger(IL.IL_IMAGE_WIDTH ),
                   IL.ilGetInteger(IL.IL_IMAGE_HEIGHT ), GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, texels);
Title: question about a texture dimension problem
Post by: tomb on August 28, 2005, 17:54:20
gluBuild3DMipmaps will upscale the texture to the closes pow2. If you don't need the mipmaps you can look at the code and see how the scaling is done.