66
77#include " stb_image_write.h"
88
9+ #include " ImGuizmo.h"
910#include " imgui.h"
1011#include " implot.h"
11- #include " ImGuizmo.h"
1212
1313#include < algorithm>
1414#include < string>
@@ -57,32 +57,35 @@ std::vector<unsigned char> getRenderInBuffer(const ScreenshotOptions& options =
5757 // I'm not sure if it's possible to do this like we want in ImGui. The alternate solution would be to save the render
5858 // from the previous render pass, but I think that comes with other problems on the Polyscope side. I'm not sure what
5959 // the answer is.
60+
61+
6062 ImGuiContext* oldContext;
6163 ImGuiContext* newContext;
6264 ImPlotContext* oldPlotContext;
6365 ImPlotContext* newPlotContext;
6466 if (options.includeUI ) {
65- // WARNING: code duplicated here and in pushContext()
67+
68+
69+ // Create a new context and push it on to the stack
70+ ImGuiIO& oldIO = ImGui::GetIO (); // used to GLFW + OpenGL data to the new IO object
6671 oldContext = ImGui::GetCurrentContext ();
67- newContext = ImGui::CreateContext ();
6872 oldPlotContext = ImPlot::GetCurrentContext ();
69- newPlotContext = ImPlot::CreateContext ();
70- ImGuiIO& oldIO = ImGui::GetIO (); // used to GLFW + OpenGL data to the new IO object
7173#ifdef IMGUI_HAS_DOCK
74+ // WARNING this code may not currently work, recent versions of imgui have changed this functionality,
75+ // and we do not regularly test with the docking branch.
7276 ImGuiPlatformIO& oldPlatformIO = ImGui::GetPlatformIO ();
7377#endif
74- ImGui::SetCurrentContext (newContext);
75- ImPlot::SetCurrentContext (newPlotContext);
76- ImGuizmo::PushContext ();
77-
78+ render::engine->createNewImGuiContext ();
79+ newContext = ImGui::GetCurrentContext ();
80+ newPlotContext = ImPlot::GetCurrentContext ();
81+ ImGui::GetIO ().ConfigFlags = oldIO.ConfigFlags ;
82+ ImGui::GetIO ().BackendFlags = oldIO.BackendFlags ;
83+ render::engine->updateImGuiContext (newContext);
7884#ifdef IMGUI_HAS_DOCK
79- // Propagate GLFW window handle to new context
85+ // see warning above
8086 ImGui::GetMainViewport ()->PlatformHandle = oldPlatformIO.Viewports [0 ]->PlatformHandle ;
8187#endif
82- ImGui::GetIO ().BackendPlatformUserData = oldIO.BackendPlatformUserData ;
83- ImGui::GetIO ().BackendRendererUserData = oldIO.BackendRendererUserData ;
84-
85- render::engine->configureImGui ();
88+ ImGuizmo::PushContext ();
8689
8790 // render a few times, to let imgui shake itself out
8891 for (int i = 0 ; i < 3 ; i++) {
@@ -106,6 +109,7 @@ std::vector<unsigned char> getRenderInBuffer(const ScreenshotOptions& options =
106109
107110 ImGui::SetCurrentContext (oldContext);
108111 ImPlot::SetCurrentContext (oldPlotContext);
112+ render::engine->updateImGuiContext (oldContext);
109113 ImGuizmo::PopContext ();
110114 }
111115
0 commit comments