Reset viewport size to current camera settings after reading the framebuffer.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9611 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
pot..om 13 years ago
parent bb631ab13a
commit a76f3a2cab
  1. 10
      engine/src/core/com/jme3/app/state/ScreenshotAppState.java

@ -6,6 +6,7 @@ import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger; import com.jme3.input.controls.KeyTrigger;
import com.jme3.post.SceneProcessor; import com.jme3.post.SceneProcessor;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager; import com.jme3.renderer.RenderManager;
import com.jme3.renderer.Renderer; import com.jme3.renderer.Renderer;
import com.jme3.renderer.ViewPort; import com.jme3.renderer.ViewPort;
@ -28,6 +29,7 @@ public class ScreenshotAppState extends AbstractAppState implements ActionListen
private String filePath = null; private String filePath = null;
private boolean capture = false; private boolean capture = false;
private Renderer renderer; private Renderer renderer;
private RenderManager rm;
private ByteBuffer outBuf; private ByteBuffer outBuf;
private String appName; private String appName;
private int shotIndex = 0; private int shotIndex = 0;
@ -92,6 +94,7 @@ public class ScreenshotAppState extends AbstractAppState implements ActionListen
public void initialize(RenderManager rm, ViewPort vp) { public void initialize(RenderManager rm, ViewPort vp) {
renderer = rm.getRenderer(); renderer = rm.getRenderer();
this.rm = rm;
reshape(vp, vp.getCamera().getWidth(), vp.getCamera().getHeight()); reshape(vp, vp.getCamera().getWidth(), vp.getCamera().getHeight());
} }
@ -117,8 +120,15 @@ public class ScreenshotAppState extends AbstractAppState implements ActionListen
capture = false; capture = false;
shotIndex++; shotIndex++;
Camera curCamera = rm.getCurrentCamera();
int viewX = (int) (curCamera.getViewPortLeft() * curCamera.getWidth());
int viewY = (int) (curCamera.getViewPortBottom() * curCamera.getHeight());
int viewWidth = (int) ((curCamera.getViewPortRight() - curCamera.getViewPortLeft()) * curCamera.getWidth());
int viewHeight = (int) ((curCamera.getViewPortTop() - curCamera.getViewPortBottom()) * curCamera.getHeight());
renderer.setViewPort(0, 0, width, height); renderer.setViewPort(0, 0, width, height);
renderer.readFrameBuffer(out, outBuf); renderer.readFrameBuffer(out, outBuf);
renderer.setViewPort(viewX, viewY, viewWidth, viewHeight);
File file; File file;
if (filePath == null) { if (filePath == null) {

Loading…
Cancel
Save