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?
For Compatibility contexts glPushAttrib()
/glPopAttrib()
with GL_VIEWPORT_BIT
will save/restore the depth range & viewport state.
In addition to @genpfault 's answer, the following also works:
// save viewport
GLint aiViewport[4];
glGetIntegerv(GL_VIEWPORT, aiViewport);
// do your stuff and then restore viewport
glViewport(aiViewport[0], aiViewport[1], (GLsizei)aiViewport[2], (GLsizei)aiViewport[3]);
This was taken from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With