Last active
March 14, 2024 05:17
-
-
Save wduminy/5859474 to your computer and use it in GitHub Desktop.
Flips a surface in SDL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SDL_Surface* flip_vertical(SDL_Surface* sfc) { | |
SDL_Surface* result = SDL_CreateRGBSurface(sfc->flags, sfc->w, sfc->h, | |
sfc->format->BytesPerPixel * 8, sfc->format->Rmask, sfc->format->Gmask, | |
sfc->format->Bmask, sfc->format->Amask); | |
const auto pitch = sfc->pitch; | |
const auto pxlength = pitch*(sfc->h - 1); | |
auto pixels = static_cast<unsigned char*>(sfc->pixels) + pxlength; | |
auto rpixels = static_cast<unsigned char*>(result->pixels) ; | |
for(auto line = 0; line < sfc->h; ++line) { | |
memcpy(rpixels,pixels,pitch); | |
pixels -= pitch; | |
rpixels += pitch; | |
} | |
return result; | |
} |
How would I approach doing this operation but for horizontal flipping
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks - I updated
line 6
:-)