< Zurück | Inhalt | Weiter >

8.4.1 Rendering an image using a Raster

A Raster object can be used to simply paste a 2D image into the 3D view. The Raster has a 3D location associated with it, and this serves as the upper−left corner of the rendered image. Note however that the image for the Raster is rendered as−is and will not have any scaling, translation, or rotation applied to it—regardless of the Raster’s position within the scenegraph. A Raster might be appropriate for graphical coordinate axis labels, for example. Since Raster is derived from Geometry it must be encapsulated by a Shape3D Node before it can be added to the scenegraph.

There are six basic steps to using a Raster:

1. Create the BufferedImage.

2. Read in or generate the image data.

3. Create the ImageComponent2D to wrap the BufferedImage.

4. Create the Raster to wrap the ImageComponent2D.

5. Create the Shape3D to contain the Raster.

6. Add the Shape3D to the scenegraph.

For example:

//create the image to be rendered using a Raster BufferedImage bufferedImage =

new BufferedImage( 128, 128, BufferedImage.TYPE_INT_RGB);

//load or do something to the image here…

//wrap the BufferedImage in an ImageComponent2D ImageComponent2D imageComponent2D =

new ImageComponent2D( ImageComponent2D.FORMAT_RGB, bufferedImage);

imageComponent2D.setCapability( ImageComponent.ALLOW_IMAGE_READ ); imageComponent2D.setCapability( ImageComponent.ALLOW_SIZE_READ );

//create the Raster for the image

m_RenderRaster = new Raster( new Point3f( 0.0f, 0.0f, 0.0f ), Raster.RASTER_COLOR,

0, 0,

bufferedImage.getWidth(), bufferedImage.getHeight(), imageComponent2D,

null );

m_RenderRaster.setCapability( Raster.ALLOW_IMAGE_WRITE ); m_RenderRaster.setCapability( Raster.ALLOW_SIZE_READ );

//wrap the Raster in a Shape3D

Shape3D shape = new Shape3D( m_RenderRaster );