2

I've heard that you need power of two texture dimensions for it to work in OpenGL. However, I've been able to load textures which are 200x200 and 300x300 (not powers of 2). Meanwhile when I tried to load a texture that is 512x512 (powers of two) with the same code but the data won't load (by the way I am using DevIL to load these pngs). I have not been able to find any thing that will tell me what type of dimensions will load. I also know that you can clip the textures and add borders but I don't know what the resulting dimensions should be.

Here is the load function:

void tex::load(std::string file)
{
    ILuint img_id = 0;
    ilGenImages(1,&img_id);
    ilBindImage(img_id);
    ilLoadImage(file.c_str());
    ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE);
    pix_data = (GLuint*)ilGetData();
    tex_width = (GLuint)ilGetInteger(IL_IMAGE_WIDTH);
    tex_height = (GLuint)ilGetInteger(IL_IMAGE_HEIGHT);
    ilDeleteImages(1,&img_id);
    //create
    glGenTextures(1,&tex_id);
    glBindTexture(GL_TEXTURE_2D,tex_id);
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,tex_width,tex_height,0,GL_RGBA,GL_UNSIGNED_BYTE,pix_data);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glBindTexture(GL_TEXTURE_2D,NULL);
}
datenwolf
  • 159,371
  • 13
  • 185
  • 298
0ctoDragon
  • 541
  • 1
  • 7
  • 20
  • Images don't need to be "power of two", in newer versions of OpenGL (Though it also depends on the GPU, etc) ... But how do you load and handle the images/textures? Kinda hard to tell you what's wrong without seeing the actual code which is in use. – vallentin Jan 12 '14 at 20:22
  • Query `MAX_TEXTURE_SIZE`, that will let you know the largest supported width/height for your 2D texture. Some extremely old GPUs do not support 512x512, but these days most support somewhere between 2048x2048 - 16384x16384. You can see statistics for such things [here](http://feedback.wildfiregames.com/report/opengl/feature/GL_MAX_TEXTURE_SIZE). – Andon M. Coleman Jan 12 '14 at 20:30
  • 3379 was the max texture size – 0ctoDragon Jan 12 '14 at 20:32
  • 1
    ***No it is not :P*** That is the constant enum that you use to ask the driver the value. Do this: `GLint max_tex_size; glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_tex_size);` – Andon M. Coleman Jan 12 '14 at 20:34
  • My bad: that gave me 8192 so 512x512 should work right – 0ctoDragon Jan 12 '14 at 20:38
  • @user2626111: Correct. And you do not have to worry about whether a texture is a power-of-two or not in anything newer than OpenGL 2.0. I suspect any issues you are experiencing are a problem with your image library and not your GL implementation. – Andon M. Coleman Jan 12 '14 at 20:52

1 Answers1

0

There are some sources that do say the maximum or at least how you can figure it out, your first step should be the OpenGL specification but for that it would be nice to know which OpenGL you are targeting. OpenGl as far as I know have a minimal maximum texture size hardcoded which is 64x64, for the actual maximum the implementation is responsible to tell you by GL_MAX_TEXTURE_SIZE you can use that in with glGet* functions this will tell you the maximum power of two texture that the implementation can handle.

On top of this OpenGL itself never mention non-power of two textures, unless it is a core feature in newer opengl versions or it is an extension.

If you want to know what combinations are actually supported again refer to the appropriate specification and it will let you know how to obtain that info.

DrakkLord
  • 645
  • 4
  • 8
  • 2
    Non-Power-of-Two textures have been a core requirement in OpenGL since 2.0. Though a lot of GPUs from that era that claimed compliance with OpenGL 2.0 did not properly support them... mostly ATI GPUs. – Andon M. Coleman Jan 12 '14 at 20:39
  • 1
    There's no requirement on minimum texture size in OpenGL. There is however a requirement on the least supported maximum texture size (i.e. no OpenGL implementation must support less than 64×64 texture size). – datenwolf Jan 12 '14 at 20:40
  • @Andon M. Coleman I can confirm that this is true based on my personal experiences. datenwolf, thanks I will fix that. – DrakkLord Jan 12 '14 at 21:11