Search code examples
c++openglmipmaps

Wrong texturing with Mipmapping in OpenGL


if I use this kind of mapping

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

my texture is working fine, but I want to get rid of pixel glitter effect like this

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);

what I see is: enter image description here

I tried with different sizes (1024x1024, 512x512, 256x256, 128x128, 64x64) with .jpg and .bmp and the effect is always something like this.


Solution

  • Assuming that your first version without mipmaps works and that you are using the same input data in both versions: The format parameter of gluBuild2DMipmaps is wrong. It seems you have RGBA data but tell OpenGL that it is RGB.