When you use glTexImage2D (...)
in your code you do not build a mipmap complete texture. It only creates storage and supplies data for texture LOD 0. If you are using GL_..._MIPMAP_...
as your minification filter you need to have LODs (levels-of-detail) for every quarter-resolution step.
For example, a texture with dimensions 32x32 requires log2 32 = 5 extra mipmap LODs, as described below:
LOD 0: 32x32 ( 1 / 1 ) [1024 Texels]
LOD 1: 16x16 ( 1 / 4 ) [ 256 Texels]
LOD 2: 8x8 ( 1 / 16 ) [ 64 Texels]
LOD 3: 4x4 ( 1 / 64 ) [ 16 Texels]
LOD 4: 2x2 ( 1 / 256 ) [ 4 Texels]
LOD 5: 1x1 ( 1 / 1024 ) [ 1 Texel ]
gluBuild2DMipmaps (...)
does a couple of things:
- It builds the set of quarter-resolution mipmap LODs (hence the name).
It properly sets the number of LODs in your texture
- Default LOD level range in an OpenGL Texture: 1001 (min = 0, max = 1000)
- After
gluBuild2DMipmaps (...)
: log2 (max (Resx, Resy)) + 1 (min = 0, max = ...).
This produces a mipmap complete texture, that can be used with a mipmap minification filter.
Miscellaneous things to note:
The default minification filter in OpenGL is: GL_NEAREST_MIPMAP_LINEAR
, so you need a mipmap complete texture unless you change it to GL_LINEAR
or GL_NEAREST
.
LOD indices in OpenGL work somewhat counter-intuitively. Lower numbers represent higher resolution images, and this is why using a negative LOD bias is sometimes referred to as "texture sharpening."
The geometric series: 1 + 1/4 + 1/16 + 1/64 + ... + 1/N converges to 4/3; mipmaps require ~33% extra storage.