ModernOpenGL Mipmap

Automatic mipmap generation


Mipmaps of a texture can be automatically generated with the glGenerateMipmap function. OpenGL 3.0 or greater is required for this function (or the extension GL_ARB_framebuffer_object). The function works quite simply; when you call it for a texture, mipmaps are generated for that texture:
http://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation




  glTexImage2D(GL_TEXTURE_2D, 0, numComponents == 3 ? GL_RGB : GL_RGBA, imageWidth, imageHeight,  0, numComponents == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, imagePtr);
  glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps now!!
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4);



 

Leave a Reply

Your email address will not be published. Required fields are marked *