Gnimuc / CImGui.jl

Julia wrapper for cimgui
https://github.com/cimgui/cimgui
MIT License
259 stars 25 forks source link

Difficulties with current Renderer.jl #66

Closed zsoerenm closed 2 years ago

zsoerenm commented 2 years ago

The current example Renderer.jl is not compatible with CImGui.jl master (which is v1.82.0 ?)

I figured, that I have to replace

using CImGui.GLFWBackend
using CImGui.OpenGLBackend
using CImGui.GLFWBackend.GLFW
using CImGui.OpenGLBackend.ModernGL

with

using CImGui.ImGuiGLFWBackend
using CImGui.ImGuiOpenGLBackend
using CImGui.ImGuiGLFWBackend.LibGLFW
using CImGui.ImGuiOpenGLBackend.ModernGL

But then I run into the next error:

ERROR: LoadError: UndefVarError: ImGui_ImplGlfw_InitForOpenGL not defined
Gnimuc commented 2 years ago

The new interfaces are init, new_frame and shutdown:

ImGuiGLFWBackend.init(window_ctx)
ImGuiOpenGLBackend.init(gl_ctx)

ImGuiOpenGLBackend.new_frame(gl_ctx)
ImGuiGLFWBackend.new_frame(window_ctx)

ImGuiOpenGLBackend.shutdown(gl_ctx)
ImGuiGLFWBackend.shutdown(window_ctx)

X-ref: https://github.com/JuliaImGui/ImGuiGLFWBackend.jl

Gnimuc commented 2 years ago

If you'd like to use the master branch, make sure you understand this unsafe_load change.

For example, igGetIO() returns a pointer of type Ptr{ImGuiIO}. With this field access method in v1.79, say we have io::Ptr{ImGuiIO}=igGetIO(), then we can run ds = io.DisplaySize to get a value ds of type ImVec2. This may look handy at the first glance. But, it does not support chaining, for example, io.DisplaySize.x cannot work as expected and it's not trivial to make it work in an efficient way. The new field access method generated by Clang.jl now returns a pointer instead of a value. io.DisplaySize.x will return a pointer and one needs to explicitly write unsafe_load(io.DisplaySize.x) to get the value. In this way, we're able to read/load/copy a single value from a big nested struct without copying the whole struct object from C to Julia. So, I think it's worth reworking everything in this new style.

Also, there is a known issue about the multi-viewport support on Windows.

I don't have time to get hands on this project at the moment, but I'd like to help and answer questions if someone would like to contribute.