From 67c9019edad10bc57e2204f75ebf96a1f1ca743a Mon Sep 17 00:00:00 2001 From: Bruno Van de Velde Date: Wed, 4 Oct 2023 08:24:49 +0200 Subject: [PATCH] Fixed texture being upside down on Android when copying the texture of a RenderTexture --- src/SFML/Graphics/Texture.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 0e9575c18..3e66898c0 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -35,6 +35,7 @@ #include +#include #include #include #include @@ -400,6 +401,22 @@ Image Texture::copyToImage() const glCheck(GLEXT_glDeleteFramebuffers(1, &frameBuffer)); glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, static_cast(previousFrameBuffer))); + + if (m_pixelsFlipped) + { + // Flip the texture vertically + const auto stride = static_cast(m_size.x * 4); + auto currentRowIterator = pixels.begin(); + auto nextRowIterator = pixels.begin() + stride; + auto reverseRowIterator = pixels.begin() + (stride * static_cast(m_size.y - 1)); + for (unsigned int i = 0; i < m_size.y / 2; ++i) + { + std::swap_ranges(currentRowIterator, nextRowIterator, reverseRowIterator); + currentRowIterator = nextRowIterator; + nextRowIterator += stride; + reverseRowIterator -= stride; + } + } } #else