ice1000 / jimgui

:sparkling_heart: Pure Java binding for dear-imgui
Apache License 2.0
185 stars 13 forks source link

Is it possible to add imgui to lwjgl? #44

Closed ejamshidiasl closed 3 years ago

ejamshidiasl commented 5 years ago

Hello i used it in java applciation and it is really good thanks

is it possible to add it to lwjgl glfw window?

ice1000 commented 5 years ago

As you can see many people have paid their souls trying to achieve this but failed:

12 #13 #18 #19 #28

ice1000 commented 5 years ago

Contribution is welcomed

ejamshidiasl commented 5 years ago

i can run 2 windows side by side but i want to run imgui window inside lwjgl i am working on it now....

ice1000 commented 5 years ago

i can run 2 windows side by side

wut? wut name/version/config of os/jre/lwjgl r u using?

ice1000 commented 5 years ago

Theoretically, exposing ImGui::CreateContext should make this possible, but I haven't tried

ice1000 commented 5 years ago

Btw,

i used it in java applciation and it is really good

what is applciation?

ejamshidiasl commented 5 years ago
import org.ice1000.jimgui.JImGui;
import org.ice1000.jimgui.util.JniLoader;
import org.lwjgl.glfw.GLFW;

public class Main {

    public Main(){
        GLFW.glfwInit();
        long window = GLFW.glfwCreateWindow(400,400,"window1",0,0);
        GLFW.glfwMakeContextCurrent(window);
        GLFW.glfwSwapInterval(1);

        GLFW.glfwShowWindow(window);

        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();
            }
        }

        while (GLFW.glfwWindowShouldClose(window) == false){
            GLFW.glfwPollEvents();

        }

        GLFW.glfwTerminate();
    }

    public static void main(String[] args){
        new Main();
    }
}
ice1000 commented 5 years ago

@ejamshidiasl you really should learn how to post codeblocks on github: https://help.github.com/en/articles/creating-and-highlighting-code-blocks

ejamshidiasl commented 5 years ago

thanks (for code blocks)

what is applciation? ---> application

ice1000 commented 5 years ago

Try JImGui.fromExistingPointer

ejamshidiasl commented 5 years ago

OS: win 10 IDE: intellij idea lwjgl: latest release

ejamshidiasl commented 5 years ago

i found something in JImGui imGui = new JImGui() there is an argumant that gets anotherWindow handle i am trying this now

ice1000 commented 5 years ago

wut

ice1000 commented 5 years ago

Try JImGui.fromExistingPointer

@ejamshidiasl

ejamshidiasl commented 5 years ago

wha is nativeObjectPtr?

ejamshidiasl commented 5 years ago

i find something cool i think problem is in imGui.initBeforeMainLoop() function because it loads other window handle

ejamshidiasl commented 5 years ago

may i ask you to change constructor? line 222 file JImGui.java please add input argument (long window)

ice1000 commented 5 years ago

I was just wrapping the native API of glfw, I have no idea how they work

ice1000 commented 5 years ago

You can use reflection to access the private initBeforeMainLoop(long) function, and prove it works, and then I can make the function public.

ejamshidiasl commented 5 years ago

Hello i downloaded new version on jimgui and now i can render it to lwjgl window but there is a problem. imgui draws on top of lwjgl so i cannot see any opengl. maybe problem is in initNewFrame

ice1000 commented 4 years ago

I have no idea, you can dig imgui itself if you'd like to

zeroeightysix commented 4 years ago

Hello i downloaded new version on jimgui and now i can render it to lwjgl window but there is a problem. imgui draws on top of lwjgl so i cannot see any opengl. maybe problem is in initNewFrame

Could you post the code for / make a new repository to show how you achieved this?

hnOsmium0001 commented 4 years ago

It occured to me that JImGui is trying to use DirectX on Windows which makes it incompatible with LWJGL. However I'm not 100% sure of this guess: is it true? If ture, how can I manually choose to use the glfw+opengl3 version?

ice1000 commented 4 years ago

I don't know. There used to be a glfw+ogl3 native library, but I can't recall how to use it.

arcogabbo commented 3 years ago

Any update for this issue? im using libgdx for a project and libgdx itself spawns a window, while imgui spawns another. My goal was to render imgui inside the libgdx existing window. I can have access to the libgdx windowhandle but passing it as argument to JImGui constructor doesnt seem to change anything. Maybe im doing something wrong?

arcogabbo commented 3 years ago

Using gui=JImGui.fromExistingPointer(windowHandle) makes the program crash and a dump is returned. Using gui=new JImGui(width,height,atlas,title,windowHandle) doesnt change anything, 2 windows appears anyway.

UPDATE: it seems on linux JImGui.fromExistingPointer(handle) doesnt crash at startup , i have only 1 window shown, but i receive an error inside the gui.render() function that makes the program crash. Im using Arch Linux and lwjgl3.

The error is the following

java: /home/ice1000/git-repos/glfw/src/posix_thread.c:64: _glfwPlatformGetTls: assertion "tls->posix.allocated == GLFW_TRUE" failed.

Any idea @ice1000 ?

videogreg93 commented 3 years ago

Why was this issue closed? I'm still not able to get this working in LibGDX.

ice1000 commented 3 years ago

Why was this issue closed? I'm still not able to get this working in LibGDX.

Me neither