From 0deeb597f18488c66920fe94c5810d8588319a3a Mon Sep 17 00:00:00 2001 From: "pot..om" Date: Sat, 28 Jul 2012 23:06:19 +0000 Subject: [PATCH] Screenshots are now supported on Android. Be Aware, file location for screenshots is now based on JmeSystem.getStorageFolder. This means that on Desktop systems, the screenshots will be placed in the user.home location instead of the application directory. Other changes include: Moved ScreenshotAppState to core, added takeScreenShot method, force glViewPort to full screen to handle cases where the last postView ViewPort isn't full screen. See post http://jmonkeyengine.org/groups/android/forum/topic/screenshotappstate-for-android/ git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9595 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/app/state/ScreenshotAppState.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) rename engine/src/{desktop => core}/com/jme3/app/state/ScreenshotAppState.java (90%) diff --git a/engine/src/desktop/com/jme3/app/state/ScreenshotAppState.java b/engine/src/core/com/jme3/app/state/ScreenshotAppState.java similarity index 90% rename from engine/src/desktop/com/jme3/app/state/ScreenshotAppState.java rename to engine/src/core/com/jme3/app/state/ScreenshotAppState.java index 639eaee6d..f970265fc 100644 --- a/engine/src/desktop/com/jme3/app/state/ScreenshotAppState.java +++ b/engine/src/core/com/jme3/app/state/ScreenshotAppState.java @@ -31,7 +31,7 @@ public class ScreenshotAppState extends AbstractAppState implements ActionListen private String appName; private int shotIndex = 0; private int width, height; - + @Override public void initialize(AppStateManager stateManager, Application app) { if (!super.isInitialized()){ @@ -45,7 +45,7 @@ public class ScreenshotAppState extends AbstractAppState implements ActionListen appName = app.getClass().getSimpleName(); } - + super.initialize(stateManager, app); } @@ -55,6 +55,10 @@ public class ScreenshotAppState extends AbstractAppState implements ActionListen } } + public void takeScreenshot() { + capture = true; + } + public void initialize(RenderManager rm, ViewPort vp) { renderer = rm.getRenderer(); reshape(vp, vp.getCamera().getWidth(), vp.getCamera().getHeight()); @@ -82,8 +86,12 @@ public class ScreenshotAppState extends AbstractAppState implements ActionListen capture = false; shotIndex++; + renderer.setViewPort(0, 0, width, height); renderer.readFrameBuffer(out, outBuf); - File file = new File(appName + shotIndex + ".png").getAbsoluteFile(); + + File file = new File(JmeSystem.getStorageFolder() + File.separator + appName + shotIndex + ".png").getAbsoluteFile(); + logger.log(Level.INFO, "Saving ScreenShot to: {0}", file.getAbsolutePath()); + OutputStream outStream = null; try { outStream = new FileOutputStream(file);