Multiple Dear ImGui contexts #7578
Replies: 1 comment
-
I use multiple contexts and I added the following at the top of imconfig.h (according ImGui docs): struct ImGuiContext; In my code I call: ImGuiIO& MainWindow::ImGuiInitialize()
} This works in multi-threaded and multiple .dlls in ImGui 1.89.6 and 1.90.6 (i didn't use any other versions). Each .dll does need to include the ImGui source and you will see one or more main SDL windows appear in which you can build your ImGui sub-windows. Each .dll will have its OWN SDL main Windows with its OWN event loop. Keep the ImGui_ImplSDL3_ProcessEvent in a variable and call it by address otherwise all your instances will be using the same context. In typedef: typedef bool (gui_ProcessEventPtr)(const SDL_Event event); In OLD SDL 3.0.0 you need to do some tweaking if you use filters. I still have that code in SDL 3.1.2 and didn't remove it, but possibly it is no longer needed. SDL 3 gave all events of ALL windows to ALL other windows. So the filter needs to use the window id to discriminate. There is a good chance that this is fixed in SDL 3.1.2., i didn't test it. In class: SDL_EventFilter sdl_fEventFilter = nullptr; I am in an event-driven system hence I need a filter to let SDL maintain the state and then send events to other queues that consume. I hope this can help or give you the beginning of a solution for your own code model. |
Beta Was this translation helpful? Give feedback.
-
First, I'm sorry, my english is poor...
Looking directly at the code.
This is my code in render loop:
` ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
In this code, the click event can't work. How to work good in multiple contexts?
I know "It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.".
But I want to draw multiple windows simultaneously, each with its own click event, and then each window will serve as a 2D texture to render at a certain position in the 3D scene. It's means one imgui-frame will save as a 2D texture, then it will used to render in 3D scene.If I need multiple 2D textures, maybe need to use multiple Dear ImGui contexts, i think so...
Beta Was this translation helpful? Give feedback.
All reactions