Skip to content

Commit

Permalink
Fixed texture being upside down on Android when copying the texture o…
Browse files Browse the repository at this point in the history
…f a RenderTexture
  • Loading branch information
texus authored and ChrisThrasher committed Oct 12, 2023
1 parent 7cd1ce1 commit 13c8a1d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/SFML/Graphics/Texture.cpp
Expand Up @@ -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<int>(m_size.x * 4);
Uint8* currentRowPtr = pixels.data();
Uint8* nextRowPtr = pixels.data() + stride;
Uint8* reverseRowPtr = pixels.data() + (stride * static_cast<int>(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
Expand Down

0 comments on commit 13c8a1d

Please sign in to comment.