Hi John,
don't know whether this helps you:

my ImageRenderCanvas works for rendering offscreen images, using a seprate 
Thread (see attachment). It worked under win2k 1.21 and 1.3 beat 1,2 and 
under linux with 1.2.1 with -Dj3d.sharedctx=false option (bad performance).

unfortunally there is another bug with the perspective (Mark from Java3D team 
told me, he submitted it), but in case your onscreen canvas is of a squared 
dimension it worked fine for me..

regards
-Michael


On Thursday 27 June 2002 20:26, John Barrus wrote:
> Kelvin,
>
> Is there no workaround right now? I don't mind rebuilding part of the
> scene graph or something if I need to.
>
> Do you know anything about the trigger? It seems like it just started
> happening a week ago, but I made several changes and I'm not sure which
> ones might have affected it.
>
> Sincerely,
>
> John B.
>
>
> -----Original Message-----
> From: Discussion list for Java 3D API
> [mailto:[EMAIL PROTECTED]] On Behalf Of Kelvin Chung
> Sent: Thursday, June 27, 2002 10:49 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [JAVA3D] Problems with off-screen rendering
>
>
> Hi John,
>
>    This is bug 4701430 -
>    Infrequent NPE at RenderBin.java:544
>
> which has a workaround in the upcoming v1.3 release.
>
> - Kelvin
> ----------------
> Java 3D Team
> Sun Microsystems Inc.
>
> >Date: Thu, 27 Jun 2002 09:43:41 -0700
>
> From: John Barrus <[EMAIL PROTECTED]>
>
> >Subject: [JAVA3D] Problems with off-screen rendering
> >To: [EMAIL PROTECTED]
> >MIME-version: 1.0
> >X-MIMEOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
> >Content-transfer-encoding: 7bit
> >Importance: Normal
> >X-Priority: 3 (Normal)
> >X-MSMail-priority: Normal
> >Delivered-to: [EMAIL PROTECTED]
> >
> >I have an application that renders to an image offscreen and then
>
> combines
>
> >the rendered image with a photograph. Unfortunately, there are times
>
> when
>
> >the render thread dies and I get the following error:
> >
> >java.lang.NullPointerException
> >        at javax.media.j3d.RenderBin.updateObject (RenderBin.java:544)
> >        at javax.media.j3d.MasterControl.updateMirrorObjects
> >(MasterControl.java:2633)
> >        at javax.media.j3d.MasterControl.runMonitor
> >(MasterControl.java:3321)
> >        at javax.media.j3d.MasterControl.doWork
>
> (MasterControl.java:2890)
>
> >        at javax.media.j3d.MasterControlThread.run
> >(MasterControlThread.java:28)
>
> From then on, I cannot render any more. I get the following
>
> >error every time I try to render the image again:
> >
> >javax.media.j3d.RestrictedAccessException: Canvas3D: Off-
> >screening rendering is in progress
> >        at javax.media.j3d.Canvas3D.renderOffScreenBuffer
> >(Canvas3D.java:1868)
> >        at app.MeshRenderer.getImage(MeshRenderer.java:716)
> >        at app.PerspectiveGrid$ImageThread.run
>
> (PerspectiveGrid.java:805)
>
> >I figured out how to detect the error, but I can't figure out how to
>
> restart
>
> >the renderer. I get an error when I try to apply stopRenderer() or
> >startRenderer() to the Canvas3D.
> >
> >Any suggestions?
> >
> >I filed a bug report with Sun.
> >
> >John Barrus
> >
> >=======================================================================
>
> ====
>
> >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".
>
> ========================================================================
> ===
> 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".
>
> ===========================================================================
> 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".
import java.awt.GraphicsConfiguration;
import java.awt.image.BufferedImage;

import javax.media.j3d.*;

/**
 *
 * @author  zero
 */
public class ImageRenderCanvas3D extends Canvas3D  {

    private BufferedImage buffer;
    private boolean printing  = false;
    private boolean started    = false;

    /** Creates a new instance of OffCanvas3D */
    public ImageRenderCanvas3D(java.awt.GraphicsConfiguration graphicsConfiguration, BufferedImage buffer) {
        super(graphicsConfiguration, true);
        this.buffer = buffer;

        int width  = buffer.getWidth();
        int height = buffer.getWidth();

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

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

        this.setOffScreenBuffer(imgBuffer);
    }


    public void start() {
        if(!started) {
            new Ready().start();
            started = true;
        }
    }

    public void postSwap() {
        super.postSwap();
        drawOffScreenBuffer();
    }

    private void drawOffScreenBuffer() {
        BufferedImage bImage = this.getOffScreenBuffer().getImage();
        buffer.getGraphics().drawImage(bImage, 0, 0, this);
    }


    private class Ready extends Thread {

        public void run() {
            while(true) {
                    waitForOffScreenRendering();
            }
        }

    }




}

Reply via email to