我正在将 GLFW 和 ImGui 用于涉及打开多个窗口的项目。到目前为止,我已经进行了设置,以便每次必须打开新窗口时,我都会生成一个线程来创建自己的 GLFW 窗口和 OpenGL 上下文。线程函数看起来像这样:
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
// Check for creation error...
glfwMakeContextCurrent(window);
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); // Is this supposed to be done per-thread?
// Calling specific impl-specific ImGui setup methods for GLFW & OpenGL3...
// Set up OpenGL stuff ...
while (!glfwWindowShouldClose(window))
{
// Some heavy-duty processing happens here...
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// ImGui code is here...
// Rendering some stuff in the window here...
// Render …Run Code Online (Sandbox Code Playgroud)