views:

318

answers:

1

I've been trying to make off screen rendering to work, using Java3D 1.5.2. In my source code I've been trying to attach an extended Canvas3D that will do off-screen rendering to SimpleUniverse, but doing so will break the render:

62.  // FOR SOME REASON THIS BREAKS RENDERING
63.  universe.getViewer().getView().addCanvas3D(canvas);

The full source code is a bit too large to paste on StackOverflow so I made it available via Pastie over here.

Line 63 has been commented out and has the ordinary Canvas3D do on-screen rendering. It will render a cube and display this in a JFrame. However if you remove the comment the off-screen render will cause the on-screen one from not rendering. Also the off-screen rendering will return a "big black nothing" BufferedImage.

I'd like to know how to make the off screen rendering work, i.e. render the scene of a rotated cube to a buffered image. I've been looking at the Java3D provided example code for off-screen rendering and they do it as this as well (with the exception that they use the Raster object to render the off screen buffer back to an on-screen window).

+1  A: 

It might be the physical dimension of the Screen3D that is wrong. The value is supposed to be size of the physical screen in meters. You can test with:

screen3D.setPhysicalScreenWidth(0.0254/90.0 * destWidth);
screen3D.setPhysicalScreenHeight(0.0254/90.0 * destHeight);

The values are from the top of the Screen3D javadoc. The problematic line worked together with the above code, at least for me :)

Setting the wrong physical dimension may also change the aspect ratio of the rendered image.

Melv
Sweet, it works! Btw do you what exactly I need to do in order to make the program exit itself. It is still running even when the rendering is done as if some resource is still running and I can't put my finger on where it is doing that. (I'm calling universe.cleanup() but that doesn't seem to be enough). I'll accept the answer after that.
Spoike
I would try .dispose() all frames. If that doesn't work, then call System.exit(0), which will kill the jvm. If you need the jvm to continue running, then more research is needed :)
Melv
Yeah, I figured out on using System.exit(0), but I don't need anything more elegant than that so it's okay. Thanks.
Spoike