From 81951f294df7f33cfa54a95f40bcf315e38eed12 Mon Sep 17 00:00:00 2001 From: nopjmp Date: Sat, 20 Feb 2021 23:15:51 -0600 Subject: [PATCH 1/3] [fix] Force initialise ImGui in the MinecraftClient constructor at return Closes #533 --- .../kami/mixin/client/MixinMinecraftClient.java | 8 ++++++++ src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinMinecraftClient.java b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinMinecraftClient.java index 440ea82fd..7463a6112 100644 --- a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinMinecraftClient.java +++ b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinMinecraftClient.java @@ -3,6 +3,7 @@ import me.zeroeightsix.kami.KamiMod; import me.zeroeightsix.kami.event.ScreenEvent; import me.zeroeightsix.kami.event.TickEvent; +import me.zeroeightsix.kami.gui.KamiImgui; import me.zeroeightsix.kami.setting.KamiConfig; import me.zeroeightsix.kami.util.Wrapper; import net.minecraft.client.MinecraftClient; @@ -10,6 +11,7 @@ import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.world.ClientWorld; import net.minecraft.util.profiler.Profiler; +import org.apache.logging.log4j.LogManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -31,6 +33,12 @@ public class MixinMinecraftClient { @Shadow private Profiler profiler; + @Inject(method = "", at = @At(value = "RETURN")) + public void init(CallbackInfo info) { + KamiImgui.INSTANCE.init(); + LogManager.getLogger("KAMI").info("ImGui initialised."); + } + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiler/Profiler;pop()V", ordinal = 0, shift = At.Shift.AFTER), cancellable = true) public void tick(CallbackInfo info) { TickEvent event; diff --git a/src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt b/src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt index 505a845a4..df0ff29cc 100644 --- a/src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt +++ b/src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt @@ -35,7 +35,7 @@ object KamiImgui { private const val minecraftiaLocation = "/assets/kami/Minecraftia.ttf" - init { + fun init() { fun addKamiFontFromTTF(filename: String, sizePixels: Float, fontCfg: ImFontConfig): ImFont? { val bytes = ByteStreams.toByteArray(javaClass.getResourceAsStream(filename) ?: return null) return ImGui.getIO().fonts.addFontFromMemoryTTF(bytes, sizePixels, fontCfg) From 39bcac3a2d84b35cb39c8980e8fd95bb096472c4 Mon Sep 17 00:00:00 2001 From: nopjmp Date: Sat, 20 Feb 2021 23:27:57 -0600 Subject: [PATCH 2/3] [enhancement] only load Minecraftia resource once --- .../me/zeroeightsix/kami/gui/KamiImgui.kt | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt b/src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt index df0ff29cc..a2454685b 100644 --- a/src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt +++ b/src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt @@ -36,8 +36,10 @@ object KamiImgui { private const val minecraftiaLocation = "/assets/kami/Minecraftia.ttf" fun init() { - fun addKamiFontFromTTF(filename: String, sizePixels: Float, fontCfg: ImFontConfig): ImFont? { - val bytes = ByteStreams.toByteArray(javaClass.getResourceAsStream(filename) ?: return null) + fun loadFontFromResources(filename: String): ByteArray? { + return ByteStreams.toByteArray(javaClass.getResourceAsStream(filename) ?: return null) + } + fun addKamiFontFromTTF(bytes: ByteArray, sizePixels: Float, fontCfg: ImFontConfig): ImFont? { return ImGui.getIO().fonts.addFontFromMemoryTTF(bytes, sizePixels, fontCfg) } @@ -55,28 +57,31 @@ object KamiImgui { return fontCfg } - addKamiFontFromTTF( - minecraftiaLocation, - 12f, - fontCfg { - oversampleH = 1 - oversampleV = 1 - pixelSnapH = true + loadFontFromResources(minecraftiaLocation)?.let { bytes -> + addKamiFontFromTTF( + bytes, + 12f, + fontCfg { + oversampleH = 1 + oversampleV = 1 + pixelSnapH = true + } + )?.let { + fonts.put("Minecraftia 12px", it) } - )?.let { - fonts.put("Minecraftia 12px", it) - } - addKamiFontFromTTF( - minecraftiaLocation, - 24f, - fontCfg { - oversampleH = 1 - oversampleV = 1 - pixelSnapH = true + addKamiFontFromTTF( + bytes, + 24f, + fontCfg { + oversampleH = 1 + oversampleV = 1 + pixelSnapH = true + } + )?.let { + fonts.put("Minecraftia 24px", it) } - )?.let { - fonts.put("Minecraftia 24px", it) } + ImGui.getIO().fonts.addFontDefault()?.let { fonts.put("Default", it) } @@ -132,4 +137,4 @@ object KamiImgui { fun mouseScroll(d: Double, e: Double) { imguiGlfw.scrollCallback(mc.window.handle, d, e) } -} \ No newline at end of file +} From 5250633f1ed0106c801c0ad05003fcb45f56fdbc Mon Sep 17 00:00:00 2001 From: nopjmp Date: Wed, 24 Feb 2021 20:29:14 -0600 Subject: [PATCH 3/3] [fix] force initialize our gLSL shaders as version 110 --- .../kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt b/src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt index a2454685b..a9a63a7da 100644 --- a/src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt +++ b/src/main/kotlin/me/zeroeightsix/kami/gui/KamiImgui.kt @@ -92,22 +92,11 @@ object KamiImgui { val defaultFontName = fontNames.getOrElse(Settings.font) { fontNames.first() } ImGui.getIO().setFontDefault(fonts[defaultFontName]) - val caps = GL.getCapabilities() - // TODO: check if this works on macOS properly. - val glslVersion = when { - caps.OpenGL32 -> { - 150 - } - caps.OpenGL30 -> { // apparently we might have to skip this one? - 130 - } - else -> 110 - } - ImGui.getIO().addConfigFlags(ImGuiConfigFlags.DockingEnable) imguiGlfw.init(mc.window.handle, false) - imguiGl.init("#version $glslVersion") + // Force 110 shaders since this is what base Minecraft uses to avoid bugs in Intel drivers. + imguiGl.init("#version 110") } internal fun frame(matrices: MatrixStack, block: () -> Unit) {