diff options
author | makamys <makamys@outlook.com> | 2022-06-23 13:18:07 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-06-23 13:18:07 +0200 |
commit | 7528004ec23e424d89ad20596a3705462d208e38 (patch) | |
tree | 330670bf484ce445e7d595767c71254afc14ea90 | |
parent | cc72faceab58271a2419458133191af4b028e2f0 (diff) | |
download | Neodymium-7528004ec23e424d89ad20596a3705462d208e38.tar.gz Neodymium-7528004ec23e424d89ad20596a3705462d208e38.tar.bz2 Neodymium-7528004ec23e424d89ad20596a3705462d208e38.zip |
Add debug key shortcut to dump texture atlas
-rw-r--r-- | src/main/java/makamys/neodymium/renderer/NeoRenderer.java | 3 | ||||
-rw-r--r-- | src/main/java/makamys/neodymium/util/Util.java | 21 |
2 files changed, 24 insertions, 0 deletions
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(); + } + } } |