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