Sewer56 / DearImguiSharp

Personal use bindings for Dear ImGui created using CppSharp
30 stars 6 forks source link

OpenTK implimentation? #2

Open Shadowblitz16 opened 2 years ago

Shadowblitz16 commented 2 years ago

Is there a way to implement this with opentk both through GameWindow and GLFW? I tried doing it the GLFW way and it won't let me cast my void pointer to your GLFWWindow class

    ImGui.ImGuiImplGlfwInitForOpenGL((GLFWwindow)window.ID.ToPointer(), true);
Shadowblitz16 commented 2 years ago

Fixed previous issue but.. Turns out I get this when using opentk...

/usr/bin/dotnet: symbol lookup error: /home/shadowblitz16/Documents/source/ZealEngine/bin/Debug/net6.0/runtimes/linux-x64/native/cimgui.so: undefined symbol: glfwSetErrorCallback
using DearImguiSharp;
//using GLFWWindow = OpenTK.Windowing.GraphicsLibraryFramework.Window;
using (var window = new Window(1080, 720, "Zeal"))
{
    var _context = ImGui.CreateContext(null);
    ImGui.StyleColorsDark(null);

    unsafe { ImGui.ImGuiImplGlfwInitForOpenGL(new GLFWwindow(window.ID.ToPointer()), true); }

    float[] vertices =
    {
        -0.5f, -0.5f, 0.0f,
        +0.5f, -0.5f, 0.0f,
        +0.0f, +0.5f, 0.0f
    };

    while (window.IsRunning(0x0000ffff))
    {   
        var open = false;
        ImGui.ImGuiImplOpenGL2NewFrame();
        ImGui.ShowDemoWindow(ref open);
        ImGui.ImGuiImplOpenGL2RenderDrawData(ImGui.GetDrawData());
    }

    ImGui.ImGuiImplOpenGL2Shutdown();
    ImGui.DestroyContext(_context);

    window.Dispose();
}
Shadowblitz16 commented 2 years ago

I also did a objdump here for your cimgui cimgui.txt

Sewer56 commented 2 years ago

I don't write native code often but if I were to have a guess it's down to the GLFW code in the wrapper not being properly configured for dynamic linking. When I added the bindings, I did the minimal required work to get CI/CD working over at NativeBuilds which uses my fork of cimgui, and I've never gotten around to testing anything other than DirectX (which is always dynamically linked since it is based on COM).

If I were to guess you might need to add some GLFW related defines in the cimgui fork, then see how goes: https://github.com/ocornut/imgui/blob/6d5388448794f76cc92576a74ad3cb17da2fca84/examples/libs/glfw/include/GLFW/glfw3.h#L178

They appear to be defined around there 👆