Java Reference
In-Depth Information
the default REPLACE texture mode in line 44. Without this, the result will contain only
one instead of the combined texture as shown.
texture In applets
There are some slight differences in using texture in applets and in applications. As il-
lustrated in Figure 15, one difference is on how the location of the texture image can be
specified. The first part of Figure 15 shows the usual loading procedure in applications,
while the second part shows the corresponding one in applets.
Specifically, note the use of the method getCodeBase() in line 3 in the second code
segment of Figure 15. Belonging to an applet class, this method will return the URL under
which the current code can be found. The name of the texture file as well as other neces-
sary path of the folder information from which the texture can be retrieved is appended
to this URL. Essentially, in applets, the complete URL must be specified in order for the
browser to locate the image file. On the other hand, loading image files in applications
usually requires the name of the files to be specified because the default is that they reside
in the same directory as the code segment.
While the loading of the image file in applets in Figure 15 is performed by finding out
the URL of the current applet, we can of course also specify the URL directly if it is fixed
and will not changed. Thus, we can also use, for example, go = new java.net.URL(http://
vlab.ee.nus.edu.sg/vlab/earth.jpg).
Figure 15. Loading texture image in Java 3D and applets
1.
TextureLoader Loader = new Texture Loader(“picture1.gif”, this);
2.
ImageComponent2D image = loader.getImage();
3.
Texture2D texture = new Texture2D();
4.
texture.setImage(0,image);
5.
Appearance appear = new Appearance();
6.
appear.setTexture(texture);
1.
java.net.URL go =null;
2.
Texture texture =null;
3.
try { go= new java.net.URL(getCodeBase().toString()+"images/earth.jpg"); }
4.
catch (java.net.MalformedURLException ex) {
5.
System.out.println(ex.getMessage());
6.
System.exit(1); }
7.
texture = new TextureLoader(go, this).getTexture();
8.
Appearance appear = new Appearance();
9.
appear.setTexture(texture);
Search WWH ::




Custom Search