Skip to main content

Offscreen rendering

7 replies [Last post]
nitro
Offline
Joined: 2004-09-12
Points: 0

Hello
I am trying to capture an image from the screen. I have seen other threads discussing this Issue, and I have follow the advice but I still does not work. I am running the 1.3.2 pre8 build.

The code is as follows:

<br />
Screen3D on=canvas.getScreen3D();<br />
Dimension dim=canvas.getSize();<br />
OffScreenCanvas3D shot=new OffScreenCanvas3D(canvas.getGraphicsConfiguration(), true);<br />
canvas.getView().addCanvas3D(shot);<br />
Screen3D off=shot.getScreen3D();<br />
off.setSize(dim);<br />
off.setPhysicalScreenHeight(dim.height);<br />
off.setPhysicalScreenWidth(dim.width);<br />
       shot.setOffScreenLocation(canvas.getLocationOnScreen());</p>
<p>BufferedImage bi=shot.doRender(dim.width, dim.height);<br />

and the error I sometimes get but not always:

<br />
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.media.j3d.Canvas3D.renderOffScreenBuffer(Unknown Source)<br />
at viewport.tools.OffScreenCanvas3D.doRender(OffScreenCanvas3D.java:59)<br />

and when i got no error the image I get is just a part of the actual scene or sometimes nothing.

I also tried it with the 1.3.1 release and there I got always a nullpointer exception except when i switched into debugging mode and set a breakpoint before OffscreenCAnvas.doRender(), the it worked correctly.

Can anybody help me?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kcr
Offline
Joined: 2004-03-17
Points: 0

> I am running the 1.3.2 pre8 build.

This is a duplicate of Issue 66 that we fixed last week. I reread your original message and noticed that you said "pre8" rather than "build8". You are running on an older daily build. Please grab build8 and it should fix your problem.

-- Kevin

nitro
Offline
Joined: 2004-09-12
Points: 0

I have now tried it also under linux with the workaround I described above (which works fine under windows and 1.3.1). Under Linux I also have 1.3.1. but if I will take the screenshot the jvm exits and i getted logged out. Has this happened before? Is this also fixed with the actual build.

jada
Offline
Joined: 2004-03-17
Points: 0

We did encounter similar problem with earlier 1.3.2 build, but we didn't verify it with 1.3.1. Anyway, we have fixed that problem in the latest 1.3.2 build8.

- Chien.

nitro
Offline
Joined: 2004-09-12
Points: 0

Here is the code I use to make a screenshot:
[code]
Canvas3D canvas=viewer.getCanvas3D();//the on screen canvas
Screen3D on=canvas.getScreen3D();

Canvas3D shot=new Canvas3D(canvas.getGraphicsConfiguration(), true);
canvas.getView().stopView();
canvas.getView().addCanvas3D(shot);
canvas.getView().startView();
Screen3D off=shot.getScreen3D();
off.setSize(on.getSize());
off.setPhysicalScreenHeight(on.getPhysicalScreenHeight());
off.setPhysicalScreenWidth(on.getPhysicalScreenWidth());
shot.setOffScreenLocation(canvas.getLocationOnScreen());
shot.setLocation(canvas.getLocationOnScreen());

BufferedImage bi = new BufferedImage(canvas.getWidth(), canvas.getHeight(), BufferedImage.TYPE_INT_ARGB);
ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bi);
shot.setOffScreenBuffer(buffer);
shot.renderOffScreenBuffer();
shot.waitForOffScreenRendering();
bi = shot.getOffScreenBuffer().getImage();
[/code]

kcr
Offline
Joined: 2004-03-17
Points: 0

This sounds like you may have uncovered a bug. Please file an issue at:

https://java3d.dev.java.net/servlets/ProjectIssues

and attach a complete test program and we will take a look at it. For more information about filing issues, please see:

https://java3d.dev.java.net/#Reporting_Issues

Note that you need to be a member of the "java3d" java.net project. If you aren't already one, please sign up as a project "Observer" at:

https://java3d.dev.java.net/servlets/ProjectMembershipRequest

Thanks.

-- Kevin

nitro
Offline
Joined: 2004-09-12
Points: 0

If I stop the view before attaching the offscren canvas and start it afterwards again everything works fine.

nitro
Offline
Joined: 2004-09-12
Points: 0

I have found the problem. I cannot add the offscreen canvas to an already active view. If I create the offscreen canvas before the scenegraph gets active it works correct.
Is this bug or is there a reason for it?