glGenerateMipmap — generate a complete set of mipmaps for a texture object
Specifies the texture target of the active texture unit to which the texture object is bound whose mipmaps will be generated. Must be one of the following symbolic constants:
glGenerateMipmap computes a complete set of mipmap arrays derived from the zero level array. Array levels up to and including the 1x1 dimension texture image are replaced with the derived arrays, regardless of previous contents. The zero level texture image is left unchanged.
The internal formats of the derived mipmap arrays all match those of the zero level texture image. The dimensions of the derived arrays are computed by halving the width and height of the zero level texture image, then in turn halving the dimensions of each array level until the 1x1 dimension texture image is reached.
The contents of the derived arrays are computed by repeated filtered reduction of the zero level array. No particular filter algorithm is required, though a box filter is recommended. glHint may be called to express a preference for speed or quality of filtering.
GL_INVALID_ENUM is generated if
target is not
GL_INVALID_OPERATION is generated if the texture bound to
target is a cube map, but its six faces do not share indentical widths, heights, formats, and types.
GL_INVALID_OPERATION is generated if either the width or height of the zero level array is not a power of two.
GL_INVALID_OPERATION is generated if the zero level array is stored in a compressed internal format.
GLuint texture_id; glGenTextures(1, &texture_id); glBindTexture(GL_TEXTURE_2D, texture_id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // texture_data is the source data of your texture, in this case // its size is sizeof(unsigned char) * texture_width * texture_height * 4 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width, texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data); glGenerateMipmap(GL_TEXTURE_2D); // Unavailable in OpenGL 2.1, use gluBuild2DMipmaps() insteads. glBindTexture(GL_TEXTURE_2D, 0);
Copyright © 2008 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.