Question regarding a snippet in GLFW/OpenGL3 implementation

int displayW, displayH;
glfwGetFramebufferSize(window, &displayW, &displayH);
glViewport(0, 0, displayW, displayH);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);

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?


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.


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