From 6df78b59a958b13464eb595195a5bc0fc68c354d Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 22 Jul 2023 14:19:09 +0900 Subject: [PATCH] screenshot taking extracted to its own function --- src/net/torvald/terrarum/App.java | 38 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/net/torvald/terrarum/App.java b/src/net/torvald/terrarum/App.java index 1676307dc..41fd078c9 100644 --- a/src/net/torvald/terrarum/App.java +++ b/src/net/torvald/terrarum/App.java @@ -571,23 +571,9 @@ public class App implements ApplicationListener { FrameBufferManager.end(); - // process screenshot request - /*if (screenshotRequested) { - FrameBufferManager.begin(postProcessorOutFBO); - try { - Pixmap p = Pixmap.createFromFrameBuffer(0, 0, postProcessorOutFBO.getWidth(), postProcessorOutFBO.getHeight()); - PixmapIO.writePNG(Gdx.files.absolute(defaultDir+"/Screenshot-"+String.valueOf(System.currentTimeMillis())+".png"), p, 9, true); - p.dispose(); - Terrarum.INSTANCE.getIngame().sendNotification("Screenshot taken"); - } - catch (Throwable e) { - e.printStackTrace(); - Terrarum.INSTANCE.getIngame().sendNotification("Failed to take screenshot: "+e.getMessage()); - } - FrameBufferManager.end(); - screenshotRequested = false; - }*/ + processScreenshotRequest(postProcessorOutFBO); + if (getConfigString("screenmagnifyingfilter").equals("hq2x") ) { @@ -595,8 +581,6 @@ public class App implements ApplicationListener { hq2x.renderToScreen(postProcessorOutFBO.getColorBufferTexture()); FrameBufferManager.end(); - - shaderPassthruRGBA.bind(); shaderPassthruRGBA.setUniformi("u_texture", 0); postProcessorOutFBO2.getColorBufferTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); @@ -635,6 +619,24 @@ public class App implements ApplicationListener { } + private static void processScreenshotRequest(FrameBuffer fb) { + if (screenshotRequested) { + FrameBufferManager.begin(fb); + try { + Pixmap p = Pixmap.createFromFrameBuffer(0, 0, fb.getWidth(), fb.getHeight()); + PixmapIO.writePNG(Gdx.files.absolute(defaultDir+"/Screenshot-"+String.valueOf(System.currentTimeMillis())+".png"), p, 9, true); + p.dispose(); + Terrarum.INSTANCE.getIngame().sendNotification("Screenshot taken"); + } + catch (Throwable e) { + e.printStackTrace(); + Terrarum.INSTANCE.getIngame().sendNotification("Failed to take screenshot: "+e.getMessage()); + } + FrameBufferManager.end(); + screenshotRequested = false; + } + } + public static Texture getCurrentDitherTex() { int hash = 31 + GLOBAL_RENDER_TIMER + 0x165667B1 + GLOBAL_RENDER_TIMER * 0xC2B2AE3D; hash = Integer.rotateLeft(hash, 17) * 0x27D4EB2F;