Can’t find it in wiki, forum and source code.
Hi,
what do you want to do exactly with that?, is it to save a screenshot as a file?
btw, you can get the height and width on the camera object, this avoid to pass the appsettings to the calls
Look at the RenderToMemory test.
Can’t find it. Where is it?
Last SVN doesn’t contains something similar.
In jMP create a new JmeTests project and select jme3tests.post.TestRenderToMemory.java
Thank you)
Following code performs screen captures to texture:
[java]
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.texture.FrameBuffer;
import com.jme3.texture.Image;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture2D;
public class ScreenCaptureHelper {
private ViewPort offScreenView;
private Texture2D texture;
private Camera mainCamera;
private Spatial scene;
private RenderManager renderManager;
public ScreenCaptureHelper(Camera mainCamera, Spatial scene, RenderManager renderManager) {
this.mainCamera = mainCamera;
this.scene = scene;
this.renderManager = renderManager;
offScreenView = new ViewPort("Offscreen View", mainCamera.clone());
offScreenView.setClearEnabled(true);
texture = new Texture2D(mainCamera.getWidth(), mainCamera.getHeight(), Image.Format.RGB8);
texture.setMinFilter(Texture.MinFilter.Trilinear);
FrameBuffer offScreenBuffer = new FrameBuffer(mainCamera.getWidth(), mainCamera.getHeight(), 0);
offScreenBuffer.setDepthBuffer(Image.Format.Depth);
offScreenBuffer.setColorTexture(texture);
offScreenView.setOutputFrameBuffer(offScreenBuffer);
offScreenView.attachScene(this.scene);
}
/**
- Captured data will be available in {@link #getTexture()} and can be applied to Picture.
- Other ways of using derived texture may result unexpected behavior
*/
public void captureScreen() {
offScreenView.getCamera().setLocation(mainCamera.getLocation());
offScreenView.getCamera().setRotation(mainCamera.getRotation());
scene.updateGeometricState();
renderManager.renderViewPort(offScreenView, 0);
}
public Texture2D getTexture() {
return texture;
}
}
[/java]
It’s rather slow (reaches 0.5 seconds), but suitable for rare screenshots
Greetings)
I want it to use last frame as background when non-fullscreen dialog (like main menu) is opened.
you can get the height and width on the camera object, this avoid to pass the appsettings to the calls
thanks, post is edited now)
oh ok.
i’m gonna add this to the snippet section
here it is http://hub.jmonkeyengine.org/groups/contribution-depot-jme3/snippets/single/15/
thank you