Skip to content
forked from ice1000/jimgui

💖 Pure Java binding for dear-imgui

License

Notifications You must be signed in to change notification settings

Mr00Anderson/jimgui

 
 

Repository files navigation

jimgui

Join the chat at https://gitter.im/imgui-java/community Download

Linux Build Windows Build
CCI AV

Cross-platform efficient pure Java binding for dear-imgui, Kotlin is used as code generation tool.

This project is created for a code editor and a game engine, both not open-sourced currently.

For macOS users, add -XstartOnFirstThread JVM argument when running programs built with jimgui.

Demo

Progress

  • ImGui namespace getter/setter/function/javadoc generation
  • ImGuiFontAtlas/ImGuiStyle/ImGuiFont/ImGuiIO/ImGuiDrawList properties getter/setter/function/javadoc generation
  • ImGui*Flags copy-pasted constant/javadoc
  • ImStyleVar keys using generic parameter as type constraint (type safe!)
  • Functions to access and modify platform window size/pos
  • Use MagicConstant annotation to specify where the constant parameters are from (IntelliJ IDEA understands this!)
    • Generate functions with MagicConstant annotation
  • Native value pointer (bool *, int *, float *) wrappers, providing accessValue and modifyValue
  • ImVec4 wrapper with optional mutability
  • Critical Native function generations
  • ImTextureID wrapper with platform-dependent implementations
    • LPDIRECT3DTEXTURE9 on WindowsXP+
    • GLuint on MacOS/Linux
  • Linux native library with glfw3 + opengl3 implementation
    • 32-bit hosted on ?
    • 64-bit hosted on CircleCI
  • WindowsXP+ native library
    • with glfw + opengl3 implementation
      • 32-bit hosted on ?
      • 64-bit hosted on my laptop
    • with directX9 implementation
      • 32-bit hosted on AppVeyor
      • 64-bit hosted on AppVeyor
  • MacOS native library with Cocoa, glut as additions to Linux implementation
    • hosted on @zxj5470 's Mac laptop

Usage

Remember to add jcenter to your repositories.

Code example

import org.ice1000.jimgui.JImGui;
import org.ice1000.jimgui.util.JniLoader;

public class Main {
	public static void main(String... args){
		JniLoader.load();
		try (JImGui imGui = new JImGui()) {
			// load fonts, global initializations, etc.
			imGui.initBeforeMainLoop();
			while (!imGui.windowShouldClose()) {
				// some drawing-irrelated initializations
				// mostly do nothing here
				imGui.initNewFrame();
				// draw your widgets here, like this
				imGui.text("Hello, World!");
				imGui.render();
			}
		}
	}
}

Notice that jimgui uses a not-very-efficient way to convert java.lang.String into byte arrays that C++ is happy with. You can customize the string-to-bytes function yourself by using org.ice1000.jimgui.util.JImGuiUtil.setStringToBytes, or use the more efficient alternative to java.lang.String -- org.ice1000.jimgui.JImStr, which is supposed to be created as global constants.

Gradle

import org.gradle.internal.os.OperatingSystem
// ...
repositories {
    // ... 
    jcenter()
}
// ...
dependencies {
  String jimgui_version = 'v0.9'
  compile "org.ice1000.jimgui:core:$jimgui_version" // basic functionality
  compile "org.ice1000.jimgui:kotlin-dsl:$jimgui_version" // kotlin dsl wrapper
}
// ...
run {
  if (OperatingSystem.current() == OperatingSystem.MAC_OS) {
    jvmArgs "-XstartOnFirstThread"
  }
}

Gradle Kotlin DSL

dependencies {
  val jimguiVersion = "v0.9"
  compile("org.ice1000.jimgui:core:$jimguiVersion") // basic functionality
  compile("org.ice1000.jimgui:kotlin-dsl:$jimguiVersion") // kotlin dsl wrapper
}

Maven

<dependency>
  <groupId>org.ice1000.jimgui</groupId>
  <!-- basic functionality -->
  <artifactId>core</artifactId>
  <version>v0.9</version>
  <type>pom</type>
</dependency>

Build

First you need to make sure you have cmake newer than 3.14 and the following software installed:

  • For Linux
    • make
    • pkg-config
    • libglfw3-dev
  • For Windows (>= XP)
    • Visual Studio 2019 with msbuild
    • DirectX 9 Libraries (should be pre-installed on Windows or with Visual Studio)
    • DirectX SDK
  • For Mac OS X
    • Everything needed on Linux
    • Cocoa
    • GLUT
    • OpenGL
    • Run with JVM Argument: -XstartOnFirstThread
      • You can use export _JAVA_OPTIONS='-XstartOnFirstThread'.

To compile a jar library, run:

$ ./gradlew assemble

To run tests, run:

$ ./gradlew test

About

💖 Pure Java binding for dear-imgui

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 35.0%
  • Kotlin 27.2%
  • C++ 22.3%
  • CMake 10.3%
  • C 5.2%