How to create texture/image from current frame in JME3?

Can’t find it in wiki, forum and source code.


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

1 Like

Thank you)

Following code performs screen captures to texture:


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());


texture = new Texture2D(mainCamera.getWidth(), mainCamera.getHeight(), Image.Format.RGB8);


FrameBuffer offScreenBuffer = new FrameBuffer(mainCamera.getWidth(), mainCamera.getHeight(), 0);







  • 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() {




    renderManager.renderViewPort(offScreenView, 0);


    public Texture2D getTexture() {

    return texture;




    It’s rather slow (reaches 0.5 seconds), but suitable for rare screenshots
1 Like


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

thank you :wink:

1 Like