Graphics Reference
In-Depth Information
Example 9-2
Loading a 2D Mipmap Chain
// Load mipmap level 0
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height,
0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
level = 1;
prevImage = &pixels[0];
while(width > 1 && height > 1)
{
int newWidth,
newHeight;
// Generate the next mipmap level
GenMipMap2D(prevImage, &newImage, width, height, &newWidth,
&newHeight);
// Load the mipmap level
glTexImage2D(GL_TEXTURE_2D, level, GL_RGB,
newWidth, newHeight, 0, GL_RGB,
GL_UNSIGNED_BYTE, newImage);
// Free the previous image
free(prevImage);
// Set the previous image for the next iteration
prevImage = newImage;
level++;
// Half the width and height
width = newWidth;
height = newHeight;
}
free(newlmage);
Two types of filtering occur when texturing: minification and magnification.
Minification is what happens when the size of the projected polygon on
the screen is smaller than the size of the texture. Magnification is what
happens when the size of the projected polygon on screen is larger than the
size of the texture. The determination of which filter type to use is handled
automatically by the hardware, but the API provides control over which type
of filtering to use in each case. For magnification, mipmapping is not relevant,
because we will always be sampling from the largest level available. For
minification, a variety of sampling modes can be used. The choice of which
mode to use is based on which level of visual quality you need to achieve and
how much performance you are willing to give up for texture filtering.
 
 
Search WWH ::




Custom Search