Search code examples
c++openglimgui

ImGui multisampling


I render my scene to FBO with multisampling. The resulting texture I use as ImGui::Image content. But how can I disable multisampling for gui? I tried:

glDisable(GL_MULTISAMPLE);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(Game::getWindow());
ImGui::NewFrame();
//...
// Some gui elements
//...
ImGui::Render();
ImGui::UpdatePlatformWindows();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glEnable(GL_MULTISAMPLE);

But this doesn't work. MSAA actually enabled when the gui drawing(text is blurred).


Solution

  • When it comes to window contexts, you can't disable MSAA after the window has been created. You need to recreate your window for it to take effect.

    I'm not sure if the same thing is needed for FBOs, however, to my knowledge calling glDisable(GL_MULTISAMPLE) at runtime only cleans up some AA state, and you can't rely on it, since it's intended that you recreate your window to make changes to MSAA, so I'd guess it probably doesn't affect your FBO the way you expect it to either.

    There's also an open issue on the ImGui repo about dealing with AA and fonts, though it seems to be "on hold" for now.