Hi,
Yes, it can be done. In fact there is no need to create
an OnScreen canvas. Check this out !
- Kelvin
--------------
Java3D Team
Sun Microsystems Inc.
>X-Unix-From: [EMAIL PROTECTED] Fri Feb 4 01:40:38 2000
>MIME-Version: 1.0
>Content-Transfer-Encoding: 7bit
>X-Priority: 3 (Normal)
>X-MSMail-Priority: Normal
>X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
>Importance: Normal
>Date: Thu, 3 Feb 2000 15:38:57 +0100
>From: Julian <[EMAIL PROTECTED]>
>Subject: [JAVA3D] AW: [JAVA3D] Printing a Canvas3D?
>To: [EMAIL PROTECTED]
>
>Vincent,
>
>I think you can configure your Canvas3D to render to an offscreen-buffer.
>You can then render the contents of the offscreen buffer onto a normal
>(non-3D) Canvas, which in effect replaces your Canvas3D on screen. You
>should then also be able to print this offscreen buffer using the print
>classes.
>
>I haven't done this yet, but the Canvas3D Documentation sounds like it
>should work.
>
>BTW: I only have the Java3D 1.2 Beta API Documentation, if you are still
>using Java3D 1.1 things might be different.
>
>
>>> Say it ain't so. I'm attempting to use the Java 2 print classes to output
>my
>>> application's Window to a printer. Everything prints fine except the
>>> Canvas3D. It always appears blank, regardless of the contents loaded into
>>> the scene. Is there a trick needed here, or am I doing something too
>weird
>>> for Java? Any code examples would be wonderful. Thanks.
>>>
>>> I thought I could grab the bits from the Canvas3D and draw them to the
>>> printer manually as an ImageIcon, but I haven't found any documentation
>or
>>> examples of how to access the bitmap being used by Canvas3D to render
>with.
>
>===========================================================================
>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".
/*
*
* "@(#)SimpleOffScreenTest.java 1.1 99/11/17"
*
* Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*/
import java.awt.*;
import java.applet.*;
import java.awt.image.BufferedImage;
import javax.media.j3d.*;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.applet.MainFrame;
public class SimpleOffScreenTest extends Applet {
static final int WIDTH = 200;
static final int HEIGHT = 200;
ImageComponent2D buffer;
public SimpleOffScreenTest() {
createOffScreenImage();
}
public void paint(Graphics g) {
g.drawImage(buffer.getImage(), 0, 0, this);
}
void createOffScreenImage() {
Canvas3D c = getOffScreenCanvas();
SimpleUniverse u = new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
BranchGroup bg = createSceneGraph();
u.addBranchGraph(bg);
createBufferImage();
c.setOffScreenBuffer(buffer);
c.renderOffScreenBuffer();
c.waitForOffScreenRendering();
}
Canvas3D getOffScreenCanvas() {
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config, true);
Screen3D scr = c.getScreen3D();
scr.setSize(new Dimension(1280, 1024));
scr.setPhysicalScreenWidth(0.36124);
scr.setPhysicalScreenHeight(0.28899555);
return c;
}
void createBufferImage() {
BufferedImage offScreenImg = new BufferedImage(WIDTH, WIDTH ,
BufferedImage.TYPE_INT_ARGB);
buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, offScreenImg);
buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);
}
BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
objRoot.addChild(new ColorCube(0.4));
return objRoot;
}
public static void main(String argv[]) {
new MainFrame(new SimpleOffScreenTest(), WIDTH, HEIGHT);
}
}