Search code examples
openglviewport

Reset glViewport after painting on framebuffer


I am painting on a large opengl canvas. At times I need to draw onto some small framebuffers (tiles) and then go back to paint to my canvas. The problem is that when I draw the framebuffers, I obviously change the viewport of the context, so when I go back painting on my canvas obviously the viewport needs to modified. What I am looking for is a way to save and restore the glViewport settings. Something like this in pseudocode:

saveViewport();
drawFramebuffers(); // this change the viewport
restoreViewport();

Is something like this possible?


Solution

  • For Compatibility contexts glPushAttrib()/glPopAttrib() with GL_VIEWPORT_BIT will save/restore the depth range & viewport state.