Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 817
reckless Avatar asked Oct 21 '25 04:10

reckless


2 Answers

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

like image 116
genpfault Avatar answered Oct 22 '25 23:10

genpfault


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

like image 25
reckless Avatar answered Oct 22 '25 23:10

reckless