From 122ebb9688e83dae749b2d556d4de0e1e27c5760 Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Thu, 2 Nov 2023 02:22:25 +0300 Subject: [PATCH] cheaper/more proper checkerboard background render (still bad) :trolley: --- .../mc/otm/client/render/RenderHelper.kt | 52 +++++++++++++++++++ .../client/screen/decorative/PainterScreen.kt | 9 +--- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/RenderHelper.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/RenderHelper.kt index e693e19cf..177c28726 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/RenderHelper.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/RenderHelper.kt @@ -105,6 +105,58 @@ fun GuiGraphics.renderRect( renderRect(pose().last().pose(), x, y, width, height, z, color) } +@Suppress("NAME_SHADOWING") +fun renderCheckerboard( + matrix: Matrix4f, + x: Float, + y: Float, + width: Float, + height: Float, + z: Float = 0f, + color: RGBAColor = RGBAColor.WHITE +) { + RenderSystem.setShader(GameRenderer::getPositionColorShader) + + RenderSystem.enableBlend() + RenderSystem.defaultBlendFunc() + + if (!is3DContext) + RenderSystem.depthFunc(GL_ALWAYS) + + val tess = tesselator + val builder = tess.builder + + builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR) + + for (i in 0 ..< width.toInt()) { + val x = x + i.toFloat() + + for (j in 0 ..< height.toInt()) { + val y = y + j.toFloat() + + if ((i + j) % 2 == 0) { + builder.vertex(matrix, x, y + 1f, z).color(color).endVertex() + builder.vertex(matrix, x + 1f, y + 1f, z).color(color).endVertex() + builder.vertex(matrix, x + 1f, y, z).color(color).endVertex() + builder.vertex(matrix, x, y, z).color(color).endVertex() + } + } + } + + tess.end() +} + +fun GuiGraphics.renderCheckerboard( + x: Float, + y: Float, + width: Float, + height: Float, + z: Float = 0f, + color: RGBAColor = RGBAColor.WHITE +) { + renderCheckerboard(pose().last().pose(), x, y, width, height, z, color) +} + fun renderTexturedRect( matrix: Matrix4f, x: Float, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/decorative/PainterScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/decorative/PainterScreen.kt index 45ff52d34..fd52916fd 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/decorative/PainterScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/decorative/PainterScreen.kt @@ -13,6 +13,7 @@ import net.minecraftforge.registries.ForgeRegistries import ru.dbotthepony.mc.otm.block.entity.decorative.PainterBlockEntity import ru.dbotthepony.mc.otm.client.render.FlatRectangleIcon import ru.dbotthepony.mc.otm.client.render.ItemStackIcon +import ru.dbotthepony.mc.otm.client.render.renderCheckerboard import ru.dbotthepony.mc.otm.client.render.renderRect import ru.dbotthepony.mc.otm.client.screen.MatteryScreen import ru.dbotthepony.mc.otm.client.screen.panels.Dock @@ -53,13 +54,7 @@ class PainterScreen(menu: PainterMenu, inventory: Inventory, title: Component) : val color = RGBAColor.rgb(dye?.textColor ?: DyeColor.LIGHT_BLUE.textColor) - val bgColor = color.copy(alpha = 0.25f) - for (x in 0 ..< width.toInt()) { - for (y in 0 ..< height.toInt()) { - if ((x + y) % 2 == 0) - graphics.renderRect(x.toFloat(), y.toFloat(), 1f, 1f, color = bgColor) - } - } + graphics.renderCheckerboard(0f, 0f, width, height, color = color.copy(alpha = 0.25f)) val multiplier = menu.dyeStoredDirect[dye]!!.toFloat() / (if (dye == null) PainterBlockEntity.MAX_WATER_STORAGE.toFloat() else PainterBlockEntity.MAX_STORAGE.toFloat()) graphics.renderRect(0f, height * (1f - multiplier), width, height * multiplier, color = color)