From 13c8a1de4e4597e1854fc2a17fef28135660c81e Mon Sep 17 00:00:00 2001 From: Bruno Van de Velde Date: Mon, 9 Oct 2023 22:50:28 +0200 Subject: [PATCH] Fixed texture being upside down on Android when copying the texture of a RenderTexture --- src/SFML/Graphics/Texture.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 9ba6eeb57..a6648bef7 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -350,6 +350,22 @@ Image Texture::copyToImage() const glCheck(GLEXT_glDeleteFramebuffers(1, &frameBuffer)); glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, previousFrameBuffer)); + + if (m_pixelsFlipped) + { + // Flip the texture vertically + const int stride = static_cast(m_size.x * 4); + Uint8* currentRowPtr = pixels.data(); + Uint8* nextRowPtr = pixels.data() + stride; + Uint8* reverseRowPtr = pixels.data() + (stride * static_cast(m_size.y - 1)); + for (unsigned int y = 0; y < m_size.y / 2; ++y) + { + std::swap_ranges(currentRowPtr, nextRowPtr, reverseRowPtr); + currentRowPtr = nextRowPtr; + nextRowPtr += stride; + reverseRowPtr -= stride; + } + } } #else