< Zurück | Inhalt | Weiter >

From AppearanceTest.java

//Create a texture loader and load the largest image (64x64−pixels) TextureLoader texLoader =

new TextureLoader( "texture00.jpg", m_Component );


//Retrieve the ImageComponent from the TextureLoader ImageComponent2D image = texLoader.getImage();


//Create a MULTI_LEVEL_MIPMAP mode Texture2D object

//based on the size of the largest image Texture2D tex2D =

new Texture2D( Texture.MULTI_LEVEL_MIPMAP, Texture.RGBA, image.getWidth(), image.getHeight() );


//Now load each of the 7 images and assign to the Texture2D for( int n = 0; n <= 6; n++ )

{

texLoader = new TextureLoader( "texture0" + n + ".jpg", m_Component );

tex2D.setImage( n, texLoader.getImage() );

}


//assign the Texture2D to the appearance m_Appearance.setTexture( m_Texture );


image


Once the graphics API has multiple texture images to choose from, it needs some criteria to decide which texture image to display. The graphics API obviously uses the texture image that is easiest to resample to the desired size; however, some more advanced options are also available. These are controlled by the setMinFilter and setMagFilter methods (table 14.3).


Table 14.3 MinFilter and MagFilter

MinFilter Option

Effect

FASTEST

Equivalent to BASE_LEVEL_POINT

NICEST

Equivalent to MULTI_LEVEL_LINEAR

BASE_LEVEL_POINT

Finds nearest texel in the level 0 texture map


BASE_LEVEL_LINEAR

Performs bilinear interpolation on the four nearest texels in the level 0 texture map

MULTI_LEVEL_POINT

Selects the nearest texel in the nearest MIPMAP


MULTI_LEVEL_LINEAR

Performs trilinear interpolation of texels between four texels each from the two nearest MIPMAP levels

FASTEST

Equivalent to BASE_LEVEL_POINT

NICEST

Equivalent to BASE_LEVEL_LINEAR

BASE_LEVEL_POINT

Selects the nearest texel in the level 0 texture map


BASE_LEVEL_LINEAR

Performs a bilinear interpolation on the four nearest texels in the level 0 texture map

Figure 14.14 illustrates how complex blending of the MIPMAP texture images can be achieved. In frame 1 the left−hand face of the cube is dominated by the level 0 texture image, which progressively passes through the 1, 2, and 3 texture images as the size of the surface is reduced through rotation (frames 2 through 4). The blending of multiple texture images obviously requires more work on the part of the graphics API.

image


Figure 14.14 Four frames from the AppearanceTest example illustrate how multiple texture images are blended when the MULTI_LEVEL_LINEAR MinFilter and BASE_LEVEL_LINEAR MagFilter are used


In contrast, when the MULTI_LEVEL_POINT mode is used, the texture images are not blended but rather different texture images are chosen for different pixels within the surface, based on the position of the pixel within the surface (figure 14.15). This is the fastest way for the graphics API to support multiple levels of detail texture images.


image

Figure 14.15 When the MULTI_LEVEL_POINT MinFilter mode is used, texture images are not blended, but rather separate images are used for different portions of the surface. The right−hand face of the cube uses the level 0 texture image at the front of the face and the level 1 texture image at the rear of the cube


MIPMAPs are a relatively easy way to improve the appearance of the texture mapping in your application. Experiment with the AppearanceTest example application to strike a good balance between texture mapping appearance and performance. Most modern graphics hardware has built−in support for MIPMAPs, although the rendering quality varies greatly depending on hardware.