Question

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).

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top