From 2e03f2b03db2efa680e5614258fe741e7adc3357 Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 4 Jan 2023 15:33:56 -0800 Subject: [PATCH] Re-add temporary allocation in BlitSurfaceTransform Unfortunately there needs to be an intermediate surface for proper alpha color blending to happen via SDL_BlitSurface. The exact SDL blending logic seems complicated and unclear for me to implement at the moment, and my attempts kind of failed, so this is just a stopgap measure to at least get the game rendering how it was before I screwed it up. --- desktop_version/src/GraphicsUtil.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/desktop_version/src/GraphicsUtil.cpp b/desktop_version/src/GraphicsUtil.cpp index 1660c525..1822ee76 100644 --- a/desktop_version/src/GraphicsUtil.cpp +++ b/desktop_version/src/GraphicsUtil.cpp @@ -220,6 +220,14 @@ static void BlitSurfaceTransform( blit_y = dest_rect->y; } + /* FIXME: Find a way to do this without allocating... */ + SDL_Surface* tempsurface = RecreateSurface(dest); + if (tempsurface == NULL) + { + return; + } + SDL_SetSurfaceBlendMode(tempsurface, SDL_BLENDMODE_BLEND); + for (int x = 0; x < orig_rect.w; x++) { for (int y = 0; y < orig_rect.h; y++) @@ -237,9 +245,12 @@ static void BlitSurfaceTransform( } const SDL_Color result = transform(pixel, color); - DrawPixel(dest, blit_x + x, blit_y + y, result); + DrawPixel(tempsurface, blit_x + x, blit_y + y, result); } } + + SDL_BlitSurface(tempsurface, NULL, dest, NULL); + VVV_freefunc(SDL_FreeSurface, tempsurface); } static SDL_Color transform_color(const SDL_Color pixel, const SDL_Color color)