Java Reference
In-Depth Information
Figure 14. Second code segment for Multitexture.java
21. Appearance createAppearance() {
22. Appearance Appear = new Appearance();
23.
24. TextureUnitState[] array = new TextureUnitState[2];
25.
TexCoordGeneration tcg = new TexCoordGeneration();
26.
tcg.setEnable(false); // use the texture coordinates set above
27.
28.
String filename = "lightmap.jpg"; System.out.println("attempt to load texture from file: "+filename);
29.
TextureLoader loader = new TextureLoader(filename, this);
30.
ImageComponent2D image = loader.getImage();
31.
if(image == null) System.out.println("load failed for texture: "+filename);
32.
Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA,
33.
image.getWidth(), image.getHeight());
34.
texture.setImage(0, image); texture.setEnable(true);
35.
36.
String filename2 = "deck.jpg"; System.out.println("attempt to load texture from file: "+filename2);
37.
TextureLoader loader2 = new TextureLoader(filename2, this);
38.
ImageComponent2D image2 = loader2.getImage();
39.
if(image2 == null) System.out.println("load failed for texture: "+filename2);
40.
Texture2D texture2 = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA,
41.
image2.getWidth(), image2.getHeight());
42.
texture2.setImage(0, image2); texture2.setEnable(true);
43.
44.
TextureAttributes ta = new TextureAttributes(); ta.setTextureMode(TextureAttributes.MODULATE);
45.
46.
TextureUnitState first = new TextureUnitState(texture,ta,tcg);
47.
first.setCapability(TextureUnitState.ALLOW_STATE_WRITE); array[0]=first;
48.
49.
TextureUnitState second = new TextureUnitState(texture2,ta,tcg);
50.
second.setCapability(TextureUnitState.ALLOW_STATE_WRITE); array[1]=second;
51.
52.
PolygonAttributes polyAttrib = new PolygonAttributes();
53.
polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
54.
Appear.setPolygonAttributes(polyAttrib);
55.
56. Appear.setTextureUnitState(array);
57. return Appear; }
integer array with both elements initialized to 0. This means that there will be 2 textures
for the geometry, both using texture coordinate set 0. Basically, the elements of setmap
are associated with corresponding elements in the TextureUnitState array instantiated in
line 24.
Line 25 creates a new TexCoordGeneration object. The automatic generation of texture
coordinates is however disabled in line 26. Instead, coordinates specified explicitly in lines
15 to 18 will be used. Another thing to note is the specification of MODULATE instead of
Search WWH ::




Custom Search