Question regarding a snippet in GLFW/OpenGL3 implementation


#1
ImGui::Render();
int displayW, displayH;
glfwMakeContextCurrent(window);
glfwGetFramebufferSize(window, &displayW, &displayH);
glViewport(0, 0, displayW, displayH);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

I’m still pretty inexperienced with graphics programming and only know a little bit about OpenGL but I usually would only call glViewport in the framebuffer size callback. Is there a reason why we get the framebuffer size and set the viewport every tick vs just doing it inside framebuffer callback?


#2

No specific reason other that dear imgui’s style is to explicitly resubmit things and avoid spaghetti/callbacks so this feels simpler and easier to read this way. Calling this again every frame will be completely negligible in term of cost.


#3

Ah okay sounds good. Thanks for the super quick reply!