Skip to content

Commit

Permalink
Implemented Viewport support
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed May 22, 2023
1 parent 018513d commit 76d11e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
14 changes: 12 additions & 2 deletions src/main/java/de/florianmichael/imguiexample/imgui/ImGuiImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

Expand All @@ -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
Expand Down

0 comments on commit 76d11e1

Please sign in to comment.