Example usage for javax.media.j3d View startView

List of usage examples for javax.media.j3d View startView

Introduction

In this page you can find the example usage for javax.media.j3d View startView.

Prototype

public final void startView() 

Source Link

Document

Starts traversing this view, and starts the renderers associated with all canvases attached to this view.

Usage

From source file:OffScreenTest.java

public void init() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    BufferedImage bImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);

    ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage);
    buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);

    Raster drawRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, 200, 200, buffer,
            null);/*from ww  w .j av  a 2  s .co m*/

    drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE);

    // create the main scene graph
    BranchGroup scene = createSceneGraph(drawRaster);

    // create the on-screen canvas
    OnScreenCanvas3D d = new OnScreenCanvas3D(config, false);
    add("Center", d);

    // create a simple universe
    u = new SimpleUniverse(d);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();

    // create an off Screen Canvas

    OffScreenCanvas3D c = new OffScreenCanvas3D(config, true, drawRaster);

    // set the offscreen to match the onscreen
    Screen3D sOn = d.getScreen3D();
    Screen3D sOff = c.getScreen3D();
    sOff.setSize(sOn.getSize());
    sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth());
    sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight());

    // attach the same view to the offscreen canvas
    View v = u.getViewer().getView();
    v.addCanvas3D(c);

    // tell onscreen about the offscreen so it knows to
    // render to the offscreen at postswap
    d.setOffScreenCanvas(c);

    u.addBranchGraph(scene);
    v.stopView();
    // Make sure that image are render completely
    // before grab it in postSwap().
    d.setImageReady();
    v.startView();

}