Example usage for javax.media.j3d ImageComponent FORMAT_RGBA

List of usage examples for javax.media.j3d ImageComponent FORMAT_RGBA

Introduction

In this page you can find the example usage for javax.media.j3d ImageComponent FORMAT_RGBA.

Prototype

int FORMAT_RGBA

To view the source code for javax.media.j3d ImageComponent FORMAT_RGBA.

Click Source Link

Document

Specifies that each pixel contains 4 8-bit channels: one each for red, green, blue, alpha.

Usage

From source file:PrintFromButton.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);/*  w w  w.ja  v a2  s  .c  o  m*/

    drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE);

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

    // create the on-screen canvas
    Canvas3D d = new Canvas3D(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 Buffer

    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
    u.getViewer().getView().addCanvas3D(c);

    // create the gui
    Button b = new Button("Print");
    b.addActionListener(this);
    Panel p = new Panel();
    p.add(b);
    add("North", p);

    u.addBranchGraph(scene);
}

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  www . j a  v  a2  s.  c  o  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();

}

From source file:ImageComponentByReferenceTest.java

public BranchGroup createSceneGraph() {
    objRoot = new BranchGroup();

    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(Group.ALLOW_CHILDREN_WRITE);

    objRoot.addChild(objTrans);/*from   ww w  .  j  a v  a2s.  co m*/

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    app.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

    textureCube = new Box(0.4f, 0.4f, 0.4f, Box.GENERATE_TEXTURE_COORDS | Box.GENERATE_NORMALS, app);
    boxShape = textureCube.getShape(Box.FRONT);
    boxShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    objTrans.addChild(textureCube);

    checkBoard = new TiledImage();
    TextureLoader texLoader = new TextureLoader(texImage, this);
    ImageComponent2D oneImage = texLoader.getImage();
    bImage1 = oneImage.getImage();

    int index = 0;
    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, false, true);

    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, true, true);

    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, false, false);

    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, true, false);

    createRaster(objRoot);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, false, true);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, true, true);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, false, false);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, true, false);

    texOne = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image[2].getWidth(), image[2].getHeight());

    texOne.setCapability(Texture.ALLOW_IMAGE_WRITE);
    texOne.setImage(0, image[2]);

    app.setTexture(texOne);

    texCheckBoard = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image[4].getWidth(), image[4].getHeight());

    texCheckBoard.setCapability(Texture.ALLOW_IMAGE_WRITE);
    objRoot.compile();
    return objRoot;
}

From source file:PrintFromButton.java

public void print(boolean toWait) {

    if (!toWait)//w w  w .  j a  v a2  s .  c  om
        printing = true;

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

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

    this.setOffScreenBuffer(buffer);
    this.renderOffScreenBuffer();

    if (toWait) {
        this.waitForOffScreenRendering();
        drawOffScreenBuffer();
    }
}

From source file:PrintFromButton.java

void drawOffScreenBuffer() {

    BufferedImage bImage = this.getOffScreenBuffer().getImage();
    ImageComponent2D newImageComponent = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage);

    drawRaster.setImage(newImageComponent);
}

From source file:PrintCanvas3D.java

BufferedImage doRender(int width, int height) {

    BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

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

    setOffScreenBuffer(buffer);/*from  w  w w .j a  v a 2  s.c  o  m*/
    renderOffScreenBuffer();
    waitForOffScreenRendering();
    bImage = getOffScreenBuffer().getImage();

    return bImage;
}