mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 13:21:51 +09:00
taking screenshot
This commit is contained in:
@@ -272,7 +272,7 @@ class SpriteAssemblerPreview: Game() {
|
||||
|
||||
if (doExport && image != null) {
|
||||
doExport = false
|
||||
PixmapIO2.writeTGAHappy(Gdx.files.absolute(exportPath), image)
|
||||
PixmapIO2.writeTGAHappy(Gdx.files.absolute(exportPath), image, false)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
@@ -140,6 +141,7 @@ public class AppLoader implements ApplicationListener {
|
||||
|
||||
private static boolean splashDisplayed = false;
|
||||
private static boolean postInitFired = false;
|
||||
private static boolean screenshotRequested = false;
|
||||
|
||||
public static LwjglApplicationConfiguration appConfig;
|
||||
public static GameFontBase fontGame;
|
||||
@@ -246,10 +248,6 @@ public class AppLoader implements ApplicationListener {
|
||||
|
||||
FrameBufferManager.begin(renderFBO);
|
||||
gdxClearAndSetBlend(.094f, .094f, .094f, 0f);
|
||||
FrameBufferManager.end();
|
||||
|
||||
|
||||
FrameBufferManager.begin(renderFBO);
|
||||
setCameraPosition(0, 0);
|
||||
|
||||
// draw splash screen when predefined screen is null
|
||||
@@ -294,6 +292,20 @@ public class AppLoader implements ApplicationListener {
|
||||
PostProcessor.INSTANCE.draw(camera.combined, renderFBO);
|
||||
|
||||
|
||||
// process screenshot request
|
||||
if (screenshotRequested) {
|
||||
screenshotRequested = false;
|
||||
|
||||
try {
|
||||
Pixmap p = ScreenUtils.getFrameBufferPixmap(0, 0, appConfig.width, appConfig.height);
|
||||
PixmapIO2.writeTGA(Gdx.files.absolute(defaultDir + "/Screenshot.tga"), p, true);
|
||||
p.dispose();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
splashDisplayed = true;
|
||||
GLOBAL_RENDER_TIMER += 1;
|
||||
}
|
||||
@@ -417,13 +429,20 @@ public class AppLoader implements ApplicationListener {
|
||||
fullscreenQuad.setIndices(new short[]{0, 1, 2, 2, 3, 0});
|
||||
}
|
||||
|
||||
public static void requestScreenshot() {
|
||||
screenshotRequested = true;
|
||||
}
|
||||
|
||||
// DEFAULT DIRECTORIES //
|
||||
|
||||
public static String OSName = System.getProperty("os.name");
|
||||
public static String OSVersion = System.getProperty("os.version");
|
||||
public static String operationSystem;
|
||||
/** %appdata%/Terrarum, without trailing slash */
|
||||
public static String defaultDir;
|
||||
/** defaultDir + "/Saves", without trailing slash */
|
||||
public static String defaultSaveDir;
|
||||
/** defaultDir + "/config.json" */
|
||||
public static String configDir;
|
||||
public static RunningEnvironment environment;
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ object CommandDict {
|
||||
"setscale" to SetScale,
|
||||
"kill" to KillActor,
|
||||
"money" to MoneyDisp,
|
||||
"screenshot" to TakeScreenshot,
|
||||
|
||||
// Test codes
|
||||
"bulletintest" to SetBulletin,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package net.torvald.terrarum.console
|
||||
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.ccG
|
||||
import net.torvald.terrarum.ccW
|
||||
import net.torvald.terrarum.ccY
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import java.time.ZonedDateTime
|
||||
import java.util.ArrayList
|
||||
import java.util.Formatter
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
@@ -20,7 +21,8 @@ internal object CommandInterpreter {
|
||||
"getlocale",
|
||||
"help",
|
||||
"version",
|
||||
"tips"
|
||||
"tips",
|
||||
"screenshot"
|
||||
)
|
||||
|
||||
internal fun execute(command: String) {
|
||||
|
||||
13
src/net/torvald/terrarum/console/TakeScreenshot.kt
Normal file
13
src/net/torvald/terrarum/console/TakeScreenshot.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package net.torvald.terrarum.console
|
||||
|
||||
import net.torvald.terrarum.AppLoader
|
||||
|
||||
object TakeScreenshot: ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
AppLoader.requestScreenshot()
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("Takes screenshot and save it to the default directory as 'screenshot.tga'")
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,9 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import javax.swing.JFileChooser
|
||||
|
||||
/**
|
||||
* This will be rendered to a postprocessor FBO
|
||||
* This will be rendered to a postprocessor FBO.
|
||||
*
|
||||
* For the entire render path, see AppLoader.
|
||||
*/
|
||||
object IngameRenderer {
|
||||
/** for non-private use, use with care! */
|
||||
@@ -282,7 +284,8 @@ object IngameRenderer {
|
||||
if (fileChooser.selectedFile != null) {
|
||||
fboRGB.inAction(null, null) {
|
||||
val p = ScreenUtils.getFrameBufferPixmap(0, 0, fboRGB.width, fboRGB.height)
|
||||
PixmapIO2.writeTGA(Gdx.files.absolute(fileChooser.selectedFile.absolutePath), p)
|
||||
PixmapIO2.writeTGA(Gdx.files.absolute(fileChooser.selectedFile.absolutePath), p, false)
|
||||
p.dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user