Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to add imgui to lwjgl? #44

Closed
ejamshidiasl opened this issue Aug 8, 2019 · 28 comments
Closed

Is it possible to add imgui to lwjgl? #44

ejamshidiasl opened this issue Aug 8, 2019 · 28 comments
Labels
good first issue Good for newcomers question Further information is requested

Comments

@ejamshidiasl
Copy link

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

is it possible to add it to lwjgl glfw window?

@ice1000
Copy link
Owner

ice1000 commented Aug 8, 2019

As you can see many people have paid their souls trying to achieve this but failed:
#12 #13 #18 #19 #28

@ice1000 ice1000 added the enhancement New feature or request label Aug 8, 2019
@ice1000
Copy link
Owner

ice1000 commented Aug 8, 2019

Contribution is welcomed

@ejamshidiasl
Copy link
Author

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

@ice1000 ice1000 added good first issue Good for newcomers question Further information is requested and removed enhancement New feature or request labels Aug 8, 2019
@ice1000
Copy link
Owner

ice1000 commented Aug 8, 2019

i can run 2 windows side by side

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

@ice1000
Copy link
Owner

ice1000 commented Aug 8, 2019

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

@ice1000
Copy link
Owner

ice1000 commented Aug 8, 2019

Btw,

i used it in java applciation and it is really good

what is applciation?

@ejamshidiasl
Copy link
Author

ejamshidiasl commented Aug 8, 2019

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
Copy link
Owner

ice1000 commented Aug 8, 2019

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

@ejamshidiasl
Copy link
Author

thanks (for code blocks)

what is applciation? ---> application

@ice1000
Copy link
Owner

ice1000 commented Aug 8, 2019

Try JImGui.fromExistingPointer

@ejamshidiasl
Copy link
Author

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

@ejamshidiasl
Copy link
Author

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

@ice1000
Copy link
Owner

ice1000 commented Aug 8, 2019

wut

@ice1000
Copy link
Owner

ice1000 commented Aug 8, 2019

Try JImGui.fromExistingPointer

@ejamshidiasl

@ejamshidiasl
Copy link
Author

wha is nativeObjectPtr?

@ejamshidiasl
Copy link
Author

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

@ejamshidiasl
Copy link
Author

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

@ice1000
Copy link
Owner

ice1000 commented Aug 8, 2019

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

@ice1000
Copy link
Owner

ice1000 commented Aug 8, 2019

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

@ejamshidiasl
Copy link
Author

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
Copy link
Owner

ice1000 commented Sep 14, 2019

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

@zeroeightysix
Copy link

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
Copy link

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
Copy link
Owner

ice1000 commented Apr 19, 2020

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

@arcogabbo
Copy link

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
Copy link

arcogabbo commented Oct 17, 2020

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
Copy link

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

@ice1000
Copy link
Owner

ice1000 commented Aug 14, 2021

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

Me neither

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants