Getting Snapshot

Hi!

I want to get a snapshot from a scene. I create scene and display it using view.renderOnce(). After that in the same program method I call view.getSnapshot(canvas, “c:/snapshot”). I really get a snapshot saved in the file. Then I try to use the same part of code in the MouseListener method mouseClicked. The method really works, I get printed supplementary comments into console but I obtain a black square in place of scene snapshot in the file.

How can I get a snapshot from a scene at some mouse (or other) event?

Create the snapshot in the rendering loop and just set a (threadsave) flag in your MouseListener. As a template how to achieve this, see the Picking example from the getting started guide.

Thanks a lot!

I’ll just add that you should not be making ANY calls to the scenegraph while it is rendering. That means your input thread (or any other thread apart from the main rendering thread) should normally just store information for later processing (like with this example).

Not doing this will more than likely cause your program to crash.

My lightweight, BSD licensed input library offers a convenient way to turn asyncronous input (e.g. AWT) into syncrhonous input which you can process in the render thread without needing heaps of booleans. For example, you can get a set of pressed keys and simply iterate through them every frame.

Will.

sorry to dig out this topic again …
but using the method ExtXith3DEnviroment.takeScreenshot( String filebase ) in this way:

proteced void loopIteration( ... ){
   ...
   		if ( takeScreen ){
			
			env.takeScreenshot("screens/shot");
			takeScreen = false;
		}
   ...
}

also results in blank black pictures … any idea anyone?

I’ve checked the Xith3DEnvironment code and it seems to look fine. I guess the error is in View.getSnapshot(Canvas3D). But I’m not deeply enough into the rendering code that I could quickly discover this error. Maybe someone else could look into it?

Anyway, I’ve modified (Ext)Xith3DEnvironment so that it takes screenshots thread safely. Now you can call takeScreenshot from any thread. But the way putting this call into the onverriden loopIteration method is just right and should in either case result in a thread safe screenshot.

Look into org.xith3d.test.render.ScreenshotTest on CVS. This should demonstrate how it should have to work. But I get only black PNGs, too.

yep … your code is fine … i tried to get a screenshot over getView.getSnapshot too without any result
what i noticed is that if i take alot screenshots (i’m trying to take some sort of animated series from my stuff) that there are many blank screens just like the one being shown in the blank screenshot image … afaik there is an additional render call for every picture, maybe this renderpass doesn’t work correctly?
i haven’t tried with lwjgl … is the lwjgl backend broken?

just another idea: could the xith internal screenshot mechanisms (as soon as they work again) write the image to disk in another thread?
something like a threaded screenshot writer:


	private class ScreenySaver extends Thread{
		
		BufferedImage screeny;
		String name;
		
		public ScreenySaver( BufferedImage screeny, String name) {
			this.screeny = screeny;
			this.name = name;
		}
		
		public void run() {
			
			try {
				ImageIO.write( screeny, "jpg", new File( "screens/" + name + ".jpg" ) );
			} catch (IOException e) {}
			
		}
		
	}

this just doesn’t interfere with the rendering

No, it isn’t. But as far as my experiences with xith and lwjgl are, the support is not as good as the JOGL/JSR-231 one. With the help of Canvas3DWrapper the usage of LWJGL should be quite easy as far as supported.

Looks good. I’ll check that.