From 2394a075d7556ef918ec9871cda6193e26c5828b Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Sun, 5 Jun 2011 05:27:28 +0200 Subject: [PATCH] Surface: Work around bug in SDL that loses per-surface alpha. A bug in SDL_ConvertSurface() leaves the per-surface alpha undefined when converting from RGBA to RGBA. This can cause problems if the surface is later converted to a format without an alpha channel, such as the display format. --- src/surface.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/surface.cpp b/src/surface.cpp index 5293617..6348a76 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -81,6 +81,11 @@ Surface::Surface(SDL_Surface *raw_, bool freeWhenDone_) Surface::Surface(Surface *s) { raw = SDL_ConvertSurface(s->raw, s->raw->format, SDL_SWSURFACE); + // Note: A bug in SDL_ConvertSurface() leaves the per-surface alpha + // undefined when converting from RGBA to RGBA. This can cause + // problems if the surface is later converted to a format without + // an alpha channel, such as the display format. + raw->format->alpha = s->raw->format->alpha; freeWhenDone = true; halfW = raw->w/2; halfH = raw->h/2;