SpaiR / imgui-java

JNI based binding for Dear ImGui
MIT License
547 stars 90 forks source link

Bug: Frames and text become black blocks in minecraft #235

Open tumuidle opened 3 days ago

tumuidle commented 3 days ago

Version

1.86.11

What happened?

Frames and text become black blocks in Minecraft MCP 1.21 when using custom fonts image

Reproduction

Initialize called after game window initialized

createContext()
ctx = getCurrentContext()
val io = getIO()

glfw.init(window, false)
gl3.init()

val fontAtlas = io.fonts
val fontConfig = ImFontConfig()

fontConfig.glyphRanges = fontAtlas.glyphRangesChineseFull
fontConfig.mergeMode = true
fontConfig.pixelSnapH = true
fontAtlas.addFontDefault(fontConfig)
fontAtlas.addFontFromMemoryTTF(loadResource("assets/h3x/NotoSansSC-Medium.otf")!!, 14f, fontConfig, fontAtlas.glyphRangesChineseFull)
fontAtlas.build()
fontConfig.destroy()

Render called after a GLFW.glfwPollEvents() call and before GLFW.glfwSwapBuffers

    fun render(window: Long) {
        glfw.newFrame()
        newFrame()

        if (begin("test", ImGuiWindowFlags.MenuBar)) {
            text("test")
        }
        end()

        render()
        MemoryStack.stackPush().use {
            val dw = it.mallocInt(1)
            val dh = it.mallocInt(1)
            GLFW.glfwGetFramebufferSize(window, dw, dh)
            RenderSystem.viewport(0, 0, dw.get(), dh.get())
        }
        gl3.renderDrawData(getDrawData())
        updatePlatformWindows()
        renderPlatformWindowsDefault()
    }

loadResource method

fun loadResource(path: String) = Main.javaClass.classLoader.getResourceAsStream(path)?.readBytes()

Relevant log output

No error in log except an asset (icons/icon_16x16.png) does not exists in MCP environment(its normal)