Coder Social home page Coder Social logo

mjkosmic / jimgui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ice1000/jimgui

0.0 1.0 0.0 746 KB

:sparkling_heart: Pure Java binding for dear-imgui

License: Apache License 2.0

Kotlin 24.96% CMake 9.52% C++ 20.40% Java 40.32% C 4.73% Perl 0.07%

jimgui's Introduction

jimgui

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

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. You can find jimgui on Maven Repositories.

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.

Using Unicode strings

You can use ImGuiFontAtlas in order to extend glyph ranges for your font, which is needed if you want to display Unicode characters. You can find more info about glyph ranges at the dear-imgui repository.

Notice that in order to display Unicode characters you need to have your Java sources encoded and compiled as UTF-8. To compile the sources as UTF-8, add the following line to your build.gradle:

compileJava.options.encoding = 'UTF-8'

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

jimgui's People

Contributors

ice1000 avatar jason0214 avatar zxj5470 avatar mr00anderson avatar hoshinotented avatar mikecovlee avatar pvik avatar gitter-badger avatar vitalline avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.