From 61adc51d09105027f55cdd37bae46745e40b8262 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Mon, 11 Jul 2011 23:42:32 +0200 Subject: [PATCH] Fixed rectangle bug in Image::CopyScreen --- src/SFML/Graphics/Image.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 4ec63578..bc5aa043 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -318,30 +318,31 @@ void Image::Copy(const Image& source, unsigned int destX, unsigned int destY, co bool Image::CopyScreen(RenderWindow& window, const IntRect& sourceRect) { // Adjust the source rectangle - IntRect srcRect = sourceRect; - if (srcRect.Width == 0 || (srcRect.Height == 0)) + IntRect rect = sourceRect; + if (rect.Width == 0 || (rect.Height == 0)) { - srcRect.Left = 0; - srcRect.Top = 0; - srcRect.Width = window.GetWidth(); - srcRect.Height = window.GetHeight(); + rect.Left = 0; + rect.Top = 0; + rect.Width = window.GetWidth(); + rect.Height = window.GetHeight(); } else { - if (srcRect.Left < 0) srcRect.Left = 0; - if (srcRect.Top < 0) srcRect.Top = 0; - if (srcRect.Width > static_cast(window.GetWidth())) srcRect.Width = window.GetWidth(); - if (srcRect.Height > static_cast(window.GetHeight())) srcRect.Height = window.GetHeight(); + if (rect.Left < 0) rect.Left = 0; + if (rect.Top < 0) rect.Top = 0; + if (rect.Width > static_cast(window.GetWidth())) rect.Width = window.GetWidth(); + if (rect.Height > static_cast(window.GetHeight())) rect.Height = window.GetHeight(); } // We can then create the texture - if (window.SetActive() && CreateTexture(srcRect.Width, srcRect.Height)) + if (window.SetActive() && CreateTexture(rect.Width, rect.Height)) { GLint previous; GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &previous)); GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture)); - GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, srcRect.Left, srcRect.Top, myWidth, myHeight)); + int y = window.GetHeight() - (rect.Top + rect.Height); // Y axis is inverted + GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rect.Left, y, myWidth, myHeight)); GLCheck(glBindTexture(GL_TEXTURE_2D, previous));