Hi,

I'm trying to figure out how to write Z-buffer data.  I have a raster
that contains both color and depth information.  While the color data is
being rendered correctly, the depth information seems to be discarded.
Is there a way to write both color and depth information?  I'd like to
be able to draw other objects from my scene graph and have them
correctly appear in front or behind objects in my raster.

The code below uses a raster with transparency, but I could do it
without transparency if necessary.

       BufferedImage bufImage;
       bufImage = new BufferedImage(150, 150,
BufferedImage.TYPE_4BYTE_ABGR);

       Graphics2D g = bufImage.createGraphics();
       g.setColor(Color.green);
       g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
       g.fillOval(0, 0, 100, 100);


g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f)); g.setColor(Color.blue); g.fillOval(50, 50, 100, 100); g.dispose();

       DepthComponentInt dc = new DepthComponentInt(150, 150);
       int[] depth = new int[150 * 150];
       for (int i = 0; i < depth.length; i++)
       {
            //As a test, give a large depth value to make raster appear
in the back of most scene geometry
           depth[i] = 100000;
       }
       dc.setDepthData(depth);


ImageComponent2D image; image = new ImageComponent2D(ImageComponent2D.FORMAT_RGBA, bufImage);

       raster = new javax.media.j3d.Raster();
       raster.setPosition(new Point3f(0, 0, 0));
       raster.setType(javax.media.j3d.Raster.RASTER_COLOR_DEPTH);
       raster.setClipMode(javax.media.j3d.Raster.CLIP_IMAGE);
       raster.setImage(image);
       raster.setDepthComponent(dc);
       raster.setSize(bufImage.getWidth(), bufImage.getHeight());


Appearance app = new Appearance(); RenderingAttributes ra = new RenderingAttributes(); ra.setDepthBufferEnable(true); ra.setDepthBufferWriteEnable(true); app.setRenderingAttributes(ra); sceneRoot.addChild(new Shape3D(raster, app));


Mark McKay

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to