diff --git a/README.md b/README.md index 5f7b0fa..7720acc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,11 @@ # Fabric ImGui Example Mod +This example contains the following features: +- Basic ImGui/ImPlot Usage +- Custom Font Rendering +- Basic Viewport implementation +- Image loading into ImGui ## Setup - For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using. ## ImGui usage @@ -15,8 +19,6 @@ ImGuiImpl.draw(io -> { }); ``` Keep in mind that ImGui needs to be initialized, so you must not remove the MinecraftClient mixin in the ImGui package -**The ImGuiImpl also contains a basic font loading base** ## License - This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects. diff --git a/src/main/java/de/florianmichael/imguiexample/imgui/ImGuiImpl.java b/src/main/java/de/florianmichael/imguiexample/imgui/ImGuiImpl.java index 10aed26..c8b7aa9 100644 --- a/src/main/java/de/florianmichael/imguiexample/imgui/ImGuiImpl.java +++ b/src/main/java/de/florianmichael/imguiexample/imgui/ImGuiImpl.java @@ -9,6 +9,7 @@ import imgui.flag.ImGuiConfigFlags; import imgui.gl3.ImGuiImplGl3; import imgui.glfw.ImGuiImplGlfw; +import org.lwjgl.glfw.GLFW; public class ImGuiImpl { private final static ImGuiImplGlfw imGuiImplGlfw = new ImGuiImplGlfw(); @@ -51,9 +52,11 @@ public static void create(final long handle) { // defaultFont = generatedFonts.get(30); // Font scale is 30 // How you can apply the font then, you can see in ExampleMixin - imGuiImplGlfw.init(handle, true); - data.setConfigFlags(ImGuiConfigFlags.DockingEnable); + // In case you want to enable Viewports on Windows, you have to do this instead of the above line: + // data.setConfigFlags(ImGuiConfigFlags.DockingEnable | ImGuiConfigFlags.ViewportsEnable); + + imGuiImplGlfw.init(handle, true); imGuiImplGl3.init(); } @@ -64,6 +67,13 @@ public static void draw(final RenderInterface runnable) { ImGui.render(); imGuiImplGl3.renderDrawData(ImGui.getDrawData()); + if (ImGui.getIO().hasConfigFlags(ImGuiConfigFlags.ViewportsEnable)) { + final long pointer = GLFW.glfwGetCurrentContext(); + ImGui.updatePlatformWindows(); + ImGui.renderPlatformWindowsDefault(); + + GLFW.glfwMakeContextCurrent(pointer); + } } // https://gist.github.com/FlorianMichael/b9d5ea2a4cb89c99e6da7dad68524c07