mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
The graphics viewport is now properly restored when switching from an active Canvas to no Canvas (resolves issue #817)
This commit is contained in:
@@ -343,6 +343,7 @@ FramebufferStrategyPackedEXT strategyPackedEXT;
|
||||
FramebufferStrategyEXT strategyEXT;
|
||||
|
||||
Canvas *Canvas::current = NULL;
|
||||
OpenGL::Viewport Canvas::systemViewport = OpenGL::Viewport();
|
||||
|
||||
static void getStrategy()
|
||||
{
|
||||
@@ -452,7 +453,7 @@ void Canvas::setupGrab()
|
||||
current->stopGrab();
|
||||
|
||||
// bind the framebuffer object.
|
||||
glPushAttrib(GL_VIEWPORT_BIT | GL_TRANSFORM_BIT);
|
||||
systemViewport = gl.getViewport();
|
||||
strategy->bindFBO(fbo);
|
||||
gl.setViewport(OpenGL::Viewport(0, 0, width, height));
|
||||
|
||||
@@ -543,7 +544,8 @@ void Canvas::stopGrab()
|
||||
strategy->bindFBO(0);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
gl.setViewport(systemViewport);
|
||||
current = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,9 @@ public:
|
||||
static Canvas *current;
|
||||
static void bindDefaultCanvas();
|
||||
|
||||
// The viewport dimensions of the system (default) framebuffer.
|
||||
static OpenGL::Viewport systemViewport;
|
||||
|
||||
GLuint getTextureName() const
|
||||
{
|
||||
return img;
|
||||
|
||||
@@ -124,9 +124,18 @@ void Graphics::setViewportSize(int width, int height)
|
||||
if (!isCreated())
|
||||
return;
|
||||
|
||||
// Set the viewport to top-left corner
|
||||
// We want to affect the main screen, not any Canvas that's currently active
|
||||
// (not that any *should* be active when this is called.)
|
||||
Canvas *c = Canvas::current;
|
||||
Canvas::bindDefaultCanvas();
|
||||
|
||||
// Set the viewport to top-left corner.
|
||||
gl.setViewport(OpenGL::Viewport(0, 0, width, height));
|
||||
|
||||
// If a canvas was bound before this function was called, it needs to be
|
||||
// made aware of the new system viewport size.
|
||||
Canvas::systemViewport = gl.getViewport();
|
||||
|
||||
// Reset the projection matrix
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
@@ -135,6 +144,10 @@ void Graphics::setViewportSize(int width, int height)
|
||||
glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
// Restore the previously active Canvas.
|
||||
if (c != nullptr)
|
||||
c->startGrab(c->getAttachedCanvases());
|
||||
}
|
||||
|
||||
bool Graphics::setMode(int width, int height)
|
||||
|
||||
Reference in New Issue
Block a user