Code Monkey home page Code Monkey logo

Comments (5)

Gnimuc avatar Gnimuc commented on July 2, 2024 1

UPDATE:

Now the master branch supports multi-viewport and this multiple contexts support is being removed since it's not recommended to use Dear ImGui in this way. Also, see #52.

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 2, 2024

These global GLFW/OpenGL states are holding temporarily only for rendering purpose. They're not ImGui states. Almost all of them are refreshed in every rendering loop when calling:

ImGui_ImplOpenGL3_NewFrame()
ImGui_ImplGlfw_NewFrame()

except g_Window and g_FontTexture. So the hot-fix would be to remove the optimization trick g_FontTexture == 0 used in this line:

g_FontTexture == 0 && ImGui_ImplOpenGL3_CreateDeviceObjects()

and make ImGui_ImplGlfw_NewFrame() aware of current GLFW window context:

function ImGui_ImplGlfw_NewFrame()

function ImGui_ImplGlfw_NewFrame(window)
    global g_Time
    global g_Window = window

then this modified example will work: https://gist.github.com/Gnimuc/b9308bb8ed0a81b4fe1e76d706837f3d

from cimgui.jl.

mchristianl avatar mchristianl commented on July 2, 2024

Thank you for the example!

except g_Window and g_FontTexture

nice.

I am still experiencing some issues with that fix, that seem to be related to the event handling: for example, in your code multicontext.jl I sometimes cannot close window1 and only window2 and sometimes the other way around.

Also it seems that currently there is no possiblity to manage the callbacks manually via

ImGui_ImplGlfw_MouseButtonCallback
ImGui_ImplGlfw_ScrollCallback
ImGui_ImplGlfw_KeyCallback
ImGui_ImplGlfw_KeyCallback

which might be of interest also for single multiple contexts.

regards,

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 2, 2024

That's because the script didn't destory GLFW windows instance in the rendering loop: https://gist.github.com/Gnimuc/b9308bb8ed0a81b4fe1e76d706837f3d#file-multicontext-jl-L118-L123
This can be fixed by something like:

# in rendering loop
GLFW.PollEvents()
if GLFW.WindowShouldClose(window1)
    CImGui.DestroyContext(ctx1)
    GLFW.DestroyWindow(window1)
end

As for the callbacks, I didn't implement that because I thought they were not very useful in that one can always overload these callbacks before GLFW initialization. But this feature is very simple to implement by following:
https://github.com/ocornut/imgui/blob/d9568c717de8ec53445bad00be73133f1a110317/examples/imgui_impl_glfw.cpp#L82-L83

so feel free to submit a PR. Or I'll fix it this weekend.

from cimgui.jl.

mchristianl avatar mchristianl commented on July 2, 2024

Indeed, I got it working in the way you proposed; the "issues" were just in my implementation. Could resolve them now

from cimgui.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.