< Zurück | Inhalt | Weiter >

From AvatarTest.java


//To set a Background image: ImageComponent2D image = new TextureLoader(

"sky.jpg", this).getScaledImage( 1300,1300 ); Background back = new Background( image ); back.setApplicationBounds( getBoundingSphere() );


//To set Background Geometry: Background back = new Background();

BranchGroup bgGeometry = new BranchGroup();


Appearance ap = new Appearance();

Texture tex = new TextureLoader( "back.jpg", this).getTexture(); ap.setTexture( tex );


Sphere sphere = new Sphere( 1.0f, Primitive.GENERATE_TEXTURE_COORDS | Primitive.GENERATE_NORMALS_INWARD, ap );


bgGeometry.addChild( sphere ); back.setGeometry( bgGeometry );


image


The foregoing examples have the effect of setting a background image. However, the second approach, using a texture−mapped sphere with the image applied, has an advantage: the texture image is automatically scaled when it is applied to the sphere. In the first example, the background image must be manually scaled to correspond to the size of the rendering window. If the rendering window is resizable, the image must be rescaled or it will merely be painted into the top left corner of the rendering window. Applying the image as a texture may also render considerably faster depending upon your rendering hardware.


In the second example, note that the normal vectors generated for the Sphere must point inward because the viewer is inside the generated Sphere and views the texture applied to the inside of the Sphere.

Alternately, the sphere’s PolygonAttributes can be set to CULL_NONE to render triangles with Normal vectors pointing away from the viewer.