A handcrafted Java binding for Dear ImGui with no dependencies and ready to use pre-compiled binaries.
It's a straightforward binding, which uses JNI to do a direct calls to Dear ImGui API.
Please read Binding notice to get more info about specific of the binding API.
See official documentation and wiki to get more info about how to do things in ImGui.
Binding doesn't force you to use backend renderer which is introduced here. Feel free to use your own render engine if you need so. See how things are done in ImGuiImplGl3.
Binding has the next version naming: imguiVersion-bindingVersion
.
For example 1.74-0.1
means that binding uses 1.74
version of ImGui and binding itself has version 0.1
.
Some of the very specific features are still in a wip state.
Make sure you have installed Java 8 or higher.
You can try this binding by yourself in a three simple steps:
git clone --branch v1.75-0.7.2 https://github.com/SpaiR/imgui-java.git
cd imgui-java
gradlew :imgui-lwjgl3:startExample
That's it! This will start an example app ImGuiGlfwExample which relies on GLFW and LWJGL3. Feel free to modify ImGuiGlfwExample#showUi method to try different ImGui widgets in action.
GIF with example: https://imgur.com/a/E2rfuCR
Usage ready build.gradle
repositories {
jcenter()
mavenCentral()
}
switch (OperatingSystem.current()) {
case OperatingSystem.LINUX:
project.ext.nativesType = "natives-linux"
break
case OperatingSystem.WINDOWS:
project.ext.nativesType = "natives-windows"
break
}
ext {
lwjglVersion = '3.2.3'
imguiVersion = '1.75-0.7.2'
}
dependencies {
implementation "io.imgui.java:binding:$imguiVersion"
implementation "io.imgui.java:lwjgl3:$imguiVersion"
runtimeOnly "io.imgui.java:$nativesType:$imguiVersion"
implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
['', '-opengl', '-glfw'].each {
implementation "org.lwjgl:lwjgl$it:$lwjglVersion"
runtimeOnly "org.lwjgl:lwjgl$it::$nativesType"
}
}
Add jcenter repository:
repositories {
jcenter()
}
Add binding dependency:
implementation 'io.imgui.java:binding:1.75-0.7.2'
If you want to use LWJGL3 renderer:
implementation 'io.imgui.java:lwjgl3:1.75-0.7.2'
Disclaimer!
LWJGL3 renderer is based on the 3.2.3
version of the LWJGL.
You'll need to add additional dependencies to it. Specifically lwjgl
itself, glfw
and opengl
modules.
You can find how to do that here.
Add binary lib dependency:
runtimeOnly "io.imgui.java:$imguiNatives:1.75-0.7.2"
Where imguiNatives
could be:
natives-linux
natives-linux-x86
natives-windows
natives-windows-x86
(x86
suffix is to get 32bit library)
Or alternatively you can download binaries manually:
Go to the /bin
folder and pick a native library for your OS. Then you'll need to provide imgui.library.path
or java.library.path
VM option with path to a folder where you've placed downloaded file.
You are ready to use imgui-java binding!
- All ImGui methods are available in
camelCase
, not inPascalCase
. - In places where you need to pass
ImVec2
orImVec4
you'll need to pass two or four float parameters respectively. If you need to getImVec2
orImVec4
, you'll need to pass a destination object as method parameter. - When you need to get an input/output to/from Dear ImGui - use primitive wrappers:
ImBool
,ImInt
etc. - Due to the Java and JNI restrictions we can't provide a fully fledged callbacks to the ImGui::InputText*() methods. Partly you could replace some of the features (like setting of the allowed chars to input) by using the ImGuiInputTextData class. Read javadoc to get more info.
To build native libraries you should install mingw-w64
and ant
. Modify GenerateLibs
to build specific binaries you need. After everything is configured, run gradlew :imgui-binding:generateLibs
.
This will build native libraries and place them in ~/imgui-binding/build/libsNative
folder.
This binding is partly based on the work of xpenatan and his version jDear-imgui.
See the LICENSE file for license rights and limitations (Apache-2.0).