mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +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;
|
FramebufferStrategyEXT strategyEXT;
|
||||||
|
|
||||||
Canvas *Canvas::current = NULL;
|
Canvas *Canvas::current = NULL;
|
||||||
|
OpenGL::Viewport Canvas::systemViewport = OpenGL::Viewport();
|
||||||
|
|
||||||
static void getStrategy()
|
static void getStrategy()
|
||||||
{
|
{
|
||||||
@@ -452,7 +453,7 @@ void Canvas::setupGrab()
|
|||||||
current->stopGrab();
|
current->stopGrab();
|
||||||
|
|
||||||
// bind the framebuffer object.
|
// bind the framebuffer object.
|
||||||
glPushAttrib(GL_VIEWPORT_BIT | GL_TRANSFORM_BIT);
|
systemViewport = gl.getViewport();
|
||||||
strategy->bindFBO(fbo);
|
strategy->bindFBO(fbo);
|
||||||
gl.setViewport(OpenGL::Viewport(0, 0, width, height));
|
gl.setViewport(OpenGL::Viewport(0, 0, width, height));
|
||||||
|
|
||||||
@@ -543,7 +544,8 @@ void Canvas::stopGrab()
|
|||||||
strategy->bindFBO(0);
|
strategy->bindFBO(0);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glPopAttrib();
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
gl.setViewport(systemViewport);
|
||||||
current = NULL;
|
current = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,6 +112,9 @@ public:
|
|||||||
static Canvas *current;
|
static Canvas *current;
|
||||||
static void bindDefaultCanvas();
|
static void bindDefaultCanvas();
|
||||||
|
|
||||||
|
// The viewport dimensions of the system (default) framebuffer.
|
||||||
|
static OpenGL::Viewport systemViewport;
|
||||||
|
|
||||||
GLuint getTextureName() const
|
GLuint getTextureName() const
|
||||||
{
|
{
|
||||||
return img;
|
return img;
|
||||||
|
|||||||
@@ -124,9 +124,18 @@ void Graphics::setViewportSize(int width, int height)
|
|||||||
if (!isCreated())
|
if (!isCreated())
|
||||||
return;
|
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));
|
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
|
// Reset the projection matrix
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
@@ -135,6 +144,10 @@ void Graphics::setViewportSize(int width, int height)
|
|||||||
glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
|
glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
|
// Restore the previously active Canvas.
|
||||||
|
if (c != nullptr)
|
||||||
|
c->startGrab(c->getAttachedCanvases());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Graphics::setMode(int width, int height)
|
bool Graphics::setMode(int width, int height)
|
||||||
|
|||||||
Reference in New Issue
Block a user