create_ponder_wonder

Exports Create ponders to disk.
git clone git://git.oshgnacknak.de/create_ponder_wonder.git
Log | Files | Refs | README

commit 85e2e2143e509ec4f13b31fa27a1699bc3cd0075
parent 8204c09d2fc6d9f9dc57b0ac9f95f9c59323f4b0
Author: Oshgnacknak <osh@oshgnacknak.de>
Date:   Fri,  9 Apr 2021 15:17:09 +0200

Move more arguments to constants + blocking render

Diffstat:
Msrc/main/java/de/oshgnacknak/create_ponder_wonder/RenderUtils.java | 124+++++++++++++++++++++++++++++--------------------------------------------------
1 file changed, 45 insertions(+), 79 deletions(-)

diff --git a/src/main/java/de/oshgnacknak/create_ponder_wonder/RenderUtils.java b/src/main/java/de/oshgnacknak/create_ponder_wonder/RenderUtils.java @@ -2,7 +2,6 @@ package de.oshgnacknak.create_ponder_wonder; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; -import io.github.noeppi_noeppi.libx.render.RenderHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.FogRenderer; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -11,9 +10,6 @@ import net.minecraft.client.shader.Framebuffer; import net.minecraft.util.ScreenShotHelper; import org.lwjgl.opengl.GL11; -import java.awt.*; -import java.io.IOException; -import java.nio.file.Path; import java.util.function.Consumer; public class RenderUtils { @@ -26,21 +22,11 @@ public class RenderUtils { private RenderUtils() {} - public static void addRenderJob(Consumer<MatrixStack> renderFunc, Path imagePath) { - Minecraft.getInstance().field_213275_aU.add(() -> render(renderFunc, imagePath)); - } + public static NativeImage render(Consumer<MatrixStack> renderFunc) { + int realWidth = scale(WIDTH); + int realHeight = scale(HEIGHT); + testForValidSize(realWidth, realHeight); - public static void render(Consumer<MatrixStack> renderFunc, Path imagePath) { - int realWidth = (int) Math.round(SCALE * WIDTH); - int realHeight = (int) Math.round(SCALE * HEIGHT); - - boolean tooLarge = false; - int maxTextureSize = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE); - if (realWidth > maxTextureSize || realHeight > maxTextureSize) { - tooLarge = true; - realWidth = 512; - realHeight = 512; - } Framebuffer fb = new Framebuffer(realWidth, realHeight, true, Minecraft.IS_RUNNING_ON_MAC); @@ -57,11 +43,7 @@ public class RenderUtils { RenderSystem.matrixMode(GL11.GL_PROJECTION); RenderSystem.loadIdentity(); - if (tooLarge) { - RenderSystem.ortho(0.0D, 512, 512, 0.0D, 1000.0D, 3000.0D); - } else { - RenderSystem.ortho(0.0D, WIDTH, HEIGHT, 0.0D, 1000.0D, 3000.0D); - } + RenderSystem.ortho(0.0D, WIDTH, HEIGHT, 0.0D, 1000.0D, 3000.0D); RenderSystem.matrixMode(GL11.GL_MODELVIEW); RenderSystem.loadIdentity(); @@ -72,76 +54,60 @@ public class RenderUtils { -Z_DISTANCE); net.minecraft.client.renderer.RenderHelper.enableGuiDepthLighting(); - IRenderTypeBuffer buffer = Minecraft.getInstance().getBufferBuilders().getEntityVertexConsumers(); - RenderSystem.defaultAlphaFunc(); - if (tooLarge) { - String[] msg = new String[]{ - "Too large", - "Your OpenGL implementation has a", - "maximum texture size", - "of " + maxTextureSize, - "this image would have had a width", - "of " + (int) Math.round(SCALE * WIDTH), - "and a height", - "of " + (int) Math.round(SCALE * HEIGHT), - "which is too large.", - "To fix this lower the scale in", - "the config."}; - matrixStack.translate(0, 0, 100); - matrixStack.scale(2, 2, 2); - for (int i = 0;i < msg.length; i++) { - Minecraft.getInstance().fontRenderer.draw(matrixStack, msg[i], 5, 5 + (i * (Minecraft.getInstance().fontRenderer.FONT_HEIGHT + 2)), Color.DARK_GRAY.getRGB()); - } - RenderHelper.resetColor(); - } else { - renderFunc.accept(matrixStack); - } + renderFunc.accept(matrixStack); RenderSystem.disableBlend(); RenderSystem.popMatrix(); NativeImage img = ScreenShotHelper.createScreenshot(realWidth, realHeight, fb); - if (INCLUDE_FRAME && !tooLarge) { - applyFrame(img, WIDTH, HEIGHT, SCALE); + if (INCLUDE_FRAME) { + applyFrame(img); } - try { - img.write(imagePath); - } catch (IOException e) { - CreatePonderWonder.LOGGER.error("Could not print recipe", e); + return img; + } + + private static void testForValidSize(int realWidth, int realHeight) { + int maxTextureSize = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE); + + if (realWidth > maxTextureSize || realHeight > maxTextureSize) { + throw new IllegalStateException(String.format( + "Image would be to large: %dx%d", + realWidth, + realHeight)); } } - private static void applyFrame(NativeImage img, int width, int height, double scale) { - img.fillAreaRGBA(scale(0, scale), scale(0, scale), scale(2, scale), scale(1, scale), 0x00000000); - img.fillAreaRGBA(scale(0, scale), scale(1, scale), scale(1, scale), scale(1, scale), 0x00000000); - img.fillAreaRGBA(scale(width - 2, scale), scale(0, scale), scale(2, scale), scale(1, scale), 0x00000000); - img.fillAreaRGBA(scale(width - 1, scale), scale(1, scale), scale(1, scale), scale(1, scale), 0x00000000); - img.fillAreaRGBA(scale(0, scale), scale(height - 1, scale), scale(2, scale), scale(1, scale), 0x00000000); - img.fillAreaRGBA(scale(0, scale), scale(height - 2, scale), scale(1, scale), scale(1, scale), 0x00000000); - img.fillAreaRGBA(scale(width - 2, scale), scale(height - 1, scale), scale(2, scale), scale(1, scale), 0x00000000); - img.fillAreaRGBA(scale(width - 1, scale), scale(height - 2, scale), scale(1, scale), scale(1, scale), 0x00000000); - - img.fillAreaRGBA(scale(1, scale), scale(1, scale), scale(1, scale), scale(1, scale), 0xFF999999); - img.fillAreaRGBA(scale(width - 2, scale), scale(1, scale), scale(1, scale), scale(1, scale), 0xFF999999); - img.fillAreaRGBA(scale(1, scale), scale(height - 2, scale), scale(1, scale), scale(1, scale), 0xFF999999); - img.fillAreaRGBA(scale(width - 2, scale), scale(height - 2, scale), scale(1, scale), scale(1, scale), 0xFF999999); - - img.fillAreaRGBA(scale(2, scale), scale(0, scale), scale(width - 4, scale), scale(1, scale), 0xFF999999); - img.fillAreaRGBA(scale(2, scale), scale(height - 1, scale), scale(width - 4, scale), scale(1, scale), 0xFF999999); - img.fillAreaRGBA(scale(0, scale), scale(2, scale), scale(1, scale), scale(height - 4, scale), 0xFF999999); - img.fillAreaRGBA(scale(width - 1, scale), scale(2, scale), scale(1, scale), scale(height - 4, scale), 0xFF999999); - - img.fillAreaRGBA(scale(2, scale), scale(1, scale), scale(width - 4, scale), scale(1, scale), 0xFFD8D8D8); - img.fillAreaRGBA(scale(2, scale), scale(height - 2, scale), scale(width - 4, scale), scale(1, scale), 0xFFB3B3B3); - img.fillAreaRGBA(scale(1, scale), scale(2, scale), scale(1, scale), scale(height - 4, scale), 0xFFD8D8D8); - img.fillAreaRGBA(scale(width - 2, scale), scale(2, scale), scale(1, scale), scale(height - 4, scale), 0xFFB3B3B3); + private static void applyFrame(NativeImage img) { + img.fillAreaRGBA(scale(0), scale(0), scale(2), scale(1), 0x00000000); + img.fillAreaRGBA(scale(0), scale(1), scale(1), scale(1), 0x00000000); + img.fillAreaRGBA(scale(WIDTH - 2), scale(0), scale(2), scale(1), 0x00000000); + img.fillAreaRGBA(scale(WIDTH - 1), scale(1), scale(1), scale(1), 0x00000000); + img.fillAreaRGBA(scale(0), scale(HEIGHT - 1), scale(2), scale(1), 0x00000000); + img.fillAreaRGBA(scale(0), scale(HEIGHT - 2), scale(1), scale(1), 0x00000000); + img.fillAreaRGBA(scale(WIDTH - 2), scale(HEIGHT - 1), scale(2), scale(1), 0x00000000); + img.fillAreaRGBA(scale(WIDTH - 1), scale(HEIGHT - 2), scale(1), scale(1), 0x00000000); + + img.fillAreaRGBA(scale(1), scale(1), scale(1), scale(1), 0xFF999999); + img.fillAreaRGBA(scale(WIDTH - 2), scale(1), scale(1), scale(1), 0xFF999999); + img.fillAreaRGBA(scale(1), scale(HEIGHT - 2), scale(1), scale(1), 0xFF999999); + img.fillAreaRGBA(scale(WIDTH - 2), scale(HEIGHT - 2), scale(1), scale(1), 0xFF999999); + + img.fillAreaRGBA(scale(2), scale(0), scale(WIDTH - 4), scale(1), 0xFF999999); + img.fillAreaRGBA(scale(2), scale(HEIGHT - 1), scale(WIDTH - 4), scale(1), 0xFF999999); + img.fillAreaRGBA(scale(0), scale(2), scale(1), scale(HEIGHT - 4), 0xFF999999); + img.fillAreaRGBA(scale(WIDTH - 1), scale(2), scale(1), scale(HEIGHT - 4), 0xFF999999); + + img.fillAreaRGBA(scale(2), scale(1), scale(WIDTH - 4), scale(1), 0xFFD8D8D8); + img.fillAreaRGBA(scale(2), scale(HEIGHT - 2), scale(WIDTH - 4), scale(1), 0xFFB3B3B3); + img.fillAreaRGBA(scale(1), scale(2), scale(1), scale(HEIGHT - 4), 0xFFD8D8D8); + img.fillAreaRGBA(scale(WIDTH - 2), scale(2), scale(1), scale(HEIGHT - 4), 0xFFB3B3B3); } - private static int scale(int value, double scale) { - return (int) Math.round(value * scale); + private static int scale(int value) { + return (int) Math.round(value * SCALE); } }