PDA

View Full Version : glGenerateMipmap() question



sam_thedancer
02-08-2013, 12:08 PM
Greetings:
The code below works fine if I uncomment gluBuild2DMipmaps() and comment out glGenerateMipmap(). But the way it is, trying to use glGenerateMipmap() to generate mipmaps, doesn't work. It seems to replace the texture with a black image. Btw, my PC supports 3.3.

Any idea what I am doing wrong?
Thanks,
Sam

glBindTexture(GL_TEXTURE_2D, texture[2]);
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_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, image[0]->sizeX, image[0]->sizeY,
// GL_RGB, GL_UNSIGNED_BYTE, image[0]->data);
glGenerateMipmap(GL_TEXTURE_2D);

Nowhere-01
02-08-2013, 12:15 PM
you may use glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

from Wiki:

Warning: It has been reported that on some ATI drivers, glGenerateMipmap(GL_TEXTURE_2D) has no effect unless you precede it with a call to glEnable(GL_TEXTURE_2D) in this particular case. Once again, to be clear, bind the texture, glEnable, then glGenerateMipmap. This is a bug and has been in the ATI drivers for a while. Perhaps by the time you read this, it will have been corrected. (glGenerateMipmap doesn't work on ATI as of 2011)

sam_thedancer
02-08-2013, 11:56 PM
Thanks, Nowhere-01.
Actually I was being dumb. I had omitted
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image[0]->sizeX, image[0]->sizeY, 0,
GL_RGB, GL_UNSIGNED_BYTE, image[0]->data);
which isn't needed with gluBuild2DMipmaps().