2

I am developing a project using GLUT, and when I want to use GlTexture to add a texture, it only works if the height and width are powers of 2 (e.g. 128x64, 256x256, etc.)

Has anyone else experienced the same problem?

My Example:

GLuint textureID;
char caminho2[1000]= "C:\\....";
glEnable(GL_TEXTURE_2D);


ilInit();
unsigned int t[2], tw, th;
unsigned char *texData;
ilGenImages(2,t);
ilBindImage(t[0]);
ilLoadImage((ILstring) caminho2);
tw = ilGetInteger(IL_IMAGE_WIDTH);
th = ilGetInteger(IL_IMAGE_HEIGHT);
ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
texData = ilGetData();


glGenTextures(1,&textureID); // unsigned int texID  - variavel global;

glBindTexture(GL_TEXTURE_2D,textureID);
glTexParameteri(GL_TEXTURE_2D,  GL_TEXTURE_WRAP_S,      GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,  GL_TEXTURE_WRAP_T,      GL_REPEAT);

glTexParameteri(GL_TEXTURE_2D,  GL_TEXTURE_MAG_FILTER,      GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,  GL_TEXTURE_MIN_FILTER,      GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);

glBindTexture(GL_TEXTURE_2D,textureID);
// draw..........
glBindTexture(GL_TEXTURE_2D,0);
genpfault
  • 51,148
  • 11
  • 85
  • 139
sAlmeida
  • 99
  • 7
  • 3
    Which version of OpenGL are you using? Check with `glGetString(GL_VERSION)`. Early versions (pre 2.0) only accepted power-of-two textures, unless the GL_ARB_non_power_of_two extension is supported. – radical7 May 10 '13 at 21:39

0 Answers0