In the Java 3D FAQ at http://tintoy.ncsa.uiuc.edu/~srp/java3d/faq.html, there is
the following
section with example code:

 How Do I...
...capture still images from Java3D in JPEG format?

     Steve Pietrowicz ([EMAIL PROTECTED]) says this can be done by getting
inside the rendering cycle and saving out the
     contents of each frame. Effectively what you do is extend Canvas3D and
override the postSwap() method. This
     method is called after J3D has rendered to the background buffer and then
swapped it to screen so you know you
     have a completed frame.

     Once the postSwap method is called, you then use the readRaster() method to
dump the raw bytes from the frame.
     You now have the option of directly dumping those bytes to disk and then
post processing them or directly saving
     them as JPEG/MPEG/whatever.

     public class CapturingCanvas extends Canvas3D
     {
       public void postSwap()
       {
         GraphicsContext3D  ctx = getGraphicsContext3D();
         Raster ras = new Raster();

         ctx.readRaster(ras);

         // Now strip out the image info
         ImageComponent2D img_src = ras.getImage();
         DepthComponent depth = ras.getDepthComponent();
         BufferedImage img = img_src.getImage();

         // write that to disk....
       }
     }

When I stick this into the Java3D Tutorial example code HelloJava3Dd.java,
to form a very simple J3D program to test canvas capturing, I get

java.lang.NullPointerException
       at javax.media.j3d.GraphicsContext3D.readRaster(
             GraphicsContext3D.java:1066)

This is in Java3D 1.1.1 for OpenGL (WinNT 4 SP 3), S3 ViRGE Graphics Card

I don't have the Java3D source code. Anyone know what's going wrong? This
exception (if caught) occurs in every postSwap() call, not just the first time.

Eric

=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to