ice1000 / jimgui

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

fromExistingPointer #18

Open Hyper157 opened 5 years ago

Hyper157 commented 5 years ago

Hello,

I'm trying to use my own GLFW window to draw Jimgui instead of the default one it creates, however I keep getting errors and crashing, perhaps a bug or wrong usage? Thank you.

public static void main(String[] args) {
        JniLoader.load();
        glfwSetErrorCallback(errorCallback);

        glfwWindowHint(GLFW_ALPHA_BITS, 8);
        glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GL_TRUE);
        glfwWindowHint(GLFW_DECORATED, GL_FALSE);

        long window = glfwCreateWindow(800, 800, "Test", 0, 0);
        if (window == 0) {
            System.exit(1);
        }

        glfwMakeContextCurrent(window);
        GL.createCapabilities();

        glfwSwapInterval(1);
        glfwSetKeyCallback(window, keyCallback);

        JImGui gui = JImGui.fromExistingPointer(window);
        gui.initBeforeMainLoop();
        while (!glfwWindowShouldClose(window)) {

            glViewport(0, 0, 800, 800);
            glClearColor(0, 0, 0, 0);
            glClear(GL_COLOR_BUFFER_BIT);

            gui.initNewFrame();
            gui.text("This is gui");
            gui.render();
        }

        glfwDestroyWindow(window);
        glfwTerminate();
        System.out.println("Terminated.");
        System.exit(0);

    }
ice1000 commented 5 years ago

Could u plz try changing

JImGui gui = JImGui.fromExistingPointer(window);
gui.initBeforeMainLoop();
while (!window.windowShouldClose()) {
    glViewport(0, 0, 800, 800);
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);

    gui.initNewFrame();
    gui.text("This is gui");
    gui.render();
}

into

JImGui gui = JImGui.fromExistingPointer(window);
gui.initBeforeMainLoop();
while (!glfwWindowShouldClose(window)) {            
    gui.initNewFrame();
    gui.text("This is gui");
    gui.render();
}
ice1000 commented 5 years ago

BTW, OS, your GLFW dependency, please.

Hyper157 commented 5 years ago

Thank you for answering,

tried doing what you told and still crashing :(

OS: Windows 10 GLFW Version: lwjgl-release-3.2.0

Crash log: hs_err_pid8812.log

ice1000 commented 5 years ago

Some related discussion #12 #13

Hyper157 commented 5 years ago

I was following some discussions about this but I couldn't fix yet

Hyper157 commented 5 years ago

Also tried your example of MultiWindows and it didn't even work, was crashing too

ice1000 commented 5 years ago

They work on Linux, and at that time I only have Linux device. Now I have Windows, but this week is the final exam week

Hyper157 commented 5 years ago

All good I'll be looking forward for updates, take your time, thank you.

Schlupps commented 5 years ago

Hi,

I have the same problem. The creation works and I get an Instance of the JimGui Class. The error occurs when I try to execute something like: imGui.text("Hello, World!");

Its some time ago when you wrote that you now have a Windows machine. I also try it in Windows 10 and GLFW 3.2.1 build 12.

Please have again a look on it. If necessary I could deliver you also some hints.

Thanks in advance.