Java Reference
In-Depth Information
Figure 11. Code segment and result for MultiLevel.java
1.
Appearance createAppearance() {
2.
int imageWidth, imageHeight, imageLevel; final int SMALLEST = 1;
3.
String filename = "color256.gif"; System.out.println("loading image: "+filename);
4.
5.
Appearance appear = new Appearance();
6.
System.out.println("loading image: "+filename);
7.
TextureLoader loader = new TextureLoader(filename, this);
8.
ImageComponent2D image = loader.getImage();
9.
if(image == null) System.out.println("load failed for texture: "+filename);
10.
11.
imageWidth = image.getWidth(); imageHeight = image.getHeight();
12.
Texture2D texture = new Texture2D(Texture.MULTI_LEVEL_MIPMAP, Texture.RGBA,
13.
imageWidth, imageHeight);
14.
15.
imageLevel = 0;
16.
System.out.println("set image level: "+imageLevel+" width: "+imageWidth+" height:”+imageHeight);
17.
texture.setImage(imageLevel, image);
18.
19.
while (imageWidth > SMALLEST || imageHeight > SMALLEST) {
20.
imageLevel++;
21.
if (imageWidth > SMALLEST) imageWidth /= 2;
22.
if (imageHeight > SMALLEST) imageHeight /= 2;
23.
System.out.print("load image level: "+imageLevel+" width: "+imageWidth
24.
+" height: "+imageHeight+" :: ");
25.
filename = "color"+imageWidth+".gif"; System.out.print(filename + " ... ");
26.
loader = new TextureLoader(filename, this);
27.
image = loader.getImage(); System.out.println("set image");
28.
texture.setImage(imageLevel, image); }
29.
30.
texture.setMagFilter(Texture.MULTI_LEVEL_POINT);
31.
texture.setMinFilter(Texture.MULTI_LEVEL_POINT);
32.
33.
appear.setTexture(texture);
34.
return appear; }
Very far
Far
Near
Search WWH ::




Custom Search