To understand how to use ImGui Java - read official documentation and wiki. Binding adopts C++ API for Java, but almost everything can be used in the same manner.
ImGui Java has a ready to use implementation for GLFW and OpenGL API using LWJGL3 library. See imgui-lwjgl3
module.
Implementation is optional, yet optional to use. Advantage of Dear ImGui is total portability, so feel free to copy-paste classes or write your own implementations.
Additionally, there is an imgui-app
module, which provides a high abstraction layer.
It hides all low-level code under one class to extend. With it, you can build your GUI application instantly.
You can support the project to motivate its further development.
Make sure you have installed JDK 8 or higher.
You can try binding by yourself in three simple steps:
git clone git@github.com:SpaiR/imgui-java.git
cd imgui-java
./gradlew :example:run
See example
module to try other widgets in action.
ImGui in LWJGL YouTube video by GamesWithGabe.
You can use this video as a basic step-by-step tutorial. It shows how to integrate binding with the usage of jar files.
Gradle and Maven dependencies could be used for this purpose as well.
Take a note, that integration itself is a very flexible process. It could be done in one way or another. If you just need a framework for your GUI - use Application module. Otherwise, if you need more control, the best way is not just to repeat steps, but to understand what each step does.
If you don't care about OpenGL and other low-level stuff, then you can use application layer from imgui-app
module.
It is a one jar solution which includes: GLFW, OpenGL and Dear ImGui itself.
So you only need one dependency line or one jar in classpath to make everything to work.
You don't need to add separate dependencies to LWJGL or native libraries, since they are already included.
Application module is the best choice if everything you care is the GUI itself.
At the same time, Application gives options to override any life-cycle method it has. That means that if you are seeking for a bit more low-level control - you can gain it as well.
A very simple application may look like this:
import imgui.ImGui;
import imgui.app.Application;
import imgui.app.Configuration;
public class Main extends Application {
@Override
protected void configure(Configuration config) {
config.setTitle("Dear ImGui is Awesome!");
}
@Override
public void process() {
ImGui.text("Hello, World!");
}
public static void main(String[] args) {
launch(new Main());
}
}
Read imgui.app.Application
javadoc to understand how it works under the hood.
If using Java 9 modules, you will need to require the imgui.app
module.
Using binding without imgui-app
module requires to "attach" it to the application manually.
You can refer to imgui-app
module to see how things are done there.
For simplicity, example of dependencies for Gradle / Maven only shows how to add natives for Windows. Feel free to add other platforms.
Native Binaries | System |
---|---|
imgui-java-natives-windows | Windows |
imgui-java-natives-linux | Linux |
imgui-java-natives-macos | macOS |
Take a note, that you also need to add dependencies to LWJGL library. Examples below shows how to do it as well.
If using Java 9 modules, ImGui Java has Automatic Module Names:
Package | Module |
---|---|
imgui-java-app | imgui.app |
imgui-java-binding | imgui.binding |
imgui-java-lwjgl3 | imgui.lwjgl3 |
imgui-java-natives-windows | imgui.natives.windows |
imgui-java-natives-linux | imgui.natives.linux |
imgui-java-natives-macos | imgui.natives.macos |
All extensions are already included in the binding and can be used as it is.
See examples in the example
module for more information about how to use them.
By default, Dear ImGui uses stb-truetype to render fonts. Yet there is an option to use FreeType font renderer. Go to the imgui_freetype to read about the difference. Binding has this option too. Freetype especially useful when you use custom font with small (~<16px) size. If you use the default font or a large font, stb will be fine for you.
There are two types of precompiled binaries: 1. with stb (the default one) 2. with freetype. You can decide by yourself, which kind of libraries for any system you want to use.
Take a note, that for Linux and macOS users using of freetype will add a dependency to the libfreetype
itself.
This is not the case for Windows users, since dll
binaries are compiled fully statically and already include freetype in themselves.
For fully portable application use default binaries.
You can still use freetype binaries for Windows builds without worry though.
For better fonts use freetype binaries.
Don't forget to make clear for your Linux/Mac users, that they will need to install freetype on their systems as well.
Use the same native libraries as you would, but with -ft
suffix in the end.
Native Binaries With FreeType | System |
---|---|
imgui-java-natives-windows-ft | Windows |
imgui-java-natives-linux-ft | Linux |
imgui-java-natives-macos-ft | macOS |
If you're using raw dll/so files, go to the release page and use libraries from the native-libraries-with-freetype.zip
archive.
Binding was made with Java usage in mind. Some places of the original library were adapted for that.
For example, in places where in C++ you need to pass a reference value, in Java you pass primitive wrappers: ImInt
, ImFloat
etc.
One important thing is how natives structs work. All of them have a public field with a pointer to the natively allocated memory.
By changing the pointer it's possible to use the same Java instance to work with different native structs.
Most of the time you can ignore this fact and just work with objects in a common way.
Read javadoc and source comments to get more info about how to do specific stuff.
Ensure you've downloaded git submodules. That could be achieved:
git clone --recurse-submodules https://github.com/SpaiR/imgui-java.git
git submodule init
+ git submodule update
./gradlew imgui-binding:generateLibs -Denvs=windows -Dlocal
./gradlew example:run -PlibPath="../imgui-binding/build/libsNative/windows64"
openjdk8
, mingw-w64-gcc
, ant
. (Package names could vary from system to system.)./gradlew imgui-binding:generateLibs -Denvs=linux -Dlocal
./gradlew example:run -PlibPath=../imgui-binding/build/libsNative/linux64
./gradlew imgui-binding:generateLibs -Denvs=macos -Dlocal
./gradlew example:run -PlibPath=../imgui-binding/build/libsNative/macosx64
In envs
parameter next values could be used windows
, linux
or macos
.
-Dlocal
is optional and means that natives will be built under the ./imgui-binding/build/
folder. Otherwise /tmp/imgui
folder will be used.
On Windows always use local build.
See the LICENSE file for license rights and limitations (MIT).