From 7528004ec23e424d89ad20596a3705462d208e38 Mon Sep 17 00:00:00 2001 From: makamys Date: Thu, 23 Jun 2022 13:18:07 +0200 Subject: Add debug key shortcut to dump texture atlas --- .../makamys/neodymium/renderer/NeoRenderer.java | 3 +++ src/main/java/makamys/neodymium/util/Util.java | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'src/main/java') diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java index f2591cb..5018e6b 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java +++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java @@ -313,6 +313,9 @@ public class NeoRenderer { //chunk.chunkMeshes[7].quadCount = 256; //setMeshVisible(chunk.chunkMeshes[7], true, true); } + if(Keyboard.isKeyDown(Keyboard.KEY_P) && !wasDown[Keyboard.KEY_P]) { + Util.dumpTexture(); + } } for(int i = 0; i < 256; i++) { wasDown[i] = Keyboard.isKeyDown(i); diff --git a/src/main/java/makamys/neodymium/util/Util.java b/src/main/java/makamys/neodymium/util/Util.java index d39ccc7..89ab1ea 100644 --- a/src/main/java/makamys/neodymium/util/Util.java +++ b/src/main/java/makamys/neodymium/util/Util.java @@ -11,6 +11,10 @@ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; +import org.apache.commons.io.FileUtils; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; + import net.minecraft.launchwrapper.Launch; public class Util { @@ -85,4 +89,21 @@ public class Util { Math.pow(y1 - y2, 2) + Math.pow(z1 - z2, 2); } + + public static void dumpTexture() { + int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH); + int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT); + + System.out.println("Dumped " + width + "x" + height + " texture."); + + ByteBuffer buf = BufferUtils.createByteBuffer(4 * width * height); + GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf); + try { + // to convert to png: + // magick -size 512x256 -depth 8 out.rgba out.png + FileUtils.writeByteArrayToFile(new File("out.rgba"), Util.byteBufferToArray(buf)); + } catch (IOException e) { + e.printStackTrace(); + } + } } -- cgit