[ Contact ] [ Links ] [ Previous : 11 / 25 : Specifying texture coordinates ] [ Up ] [ Next : 13 / 25 : Texture coordinates Second example codet ]

Texture2D example code

Load a texture image

TextureLoader myLoader = new TextureLoader( "brick.jpg", this );
ImageComponent2D myImage = myLoader.getImage( );

or without the util classes

Toolkit tk = Toolkit.getDefaultToolkit();
   
img = tk.getImage("AnyImage.gif");
   
try {
	MediaTracker tracker = new MediaTracker(this);
	tracker.addImage(img, 0);
	tracker.waitForID(0);
	}
catch ( Exception e ) {}

ImageComponent2D image = 
	new ImageComponent2D(ImageComponent2D.FORMAT_RGB, img);

Create a Texture2D using the image (ImageComponent2D), and turn it on

Texture2D myTex = new Texture2D( );
myTex.setImage( 0, myImage );
myTex.setEnable( true );

Create an Appearance and set the texture in it

Appearance myAppear = new Appearance( );
myAppear.setTexture( myTex );

Assemble the shape

Shape3D myShape = new Shape3D( myText, myAppear );


See the "Links" link above to find out the sources of the proposed informations
Pascal Vuylsteker / eScience / Computer Science / ANU
Last modified: 20/4/2004
TOC - Print
Send your comments at :
<Hugh.Fisher@anu.edu.au>