From ec1beaa2ee07368368e9bd45fe400eedc57419eb Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 21 Aug 2013 14:37:03 +0300 Subject: first part of fixes for compilation with SDL2 --- src/resources/atlasmanager.cpp | 4 ++++ src/resources/image.cpp | 7 ++++++- src/resources/imagehelper.cpp | 4 ++++ src/resources/openglimagehelper.cpp | 4 ++++ src/resources/sdlimagehelper.cpp | 13 ++++++++++++- src/resources/sdlmusic.cpp | 4 ++++ 6 files changed, 34 insertions(+), 2 deletions(-) (limited to 'src/resources') diff --git a/src/resources/atlasmanager.cpp b/src/resources/atlasmanager.cpp index 1d7147d72..1292baeb7 100644 --- a/src/resources/atlasmanager.cpp +++ b/src/resources/atlasmanager.cpp @@ -239,7 +239,11 @@ SDL_Surface *AtlasManager::createSDLAtlas(TextureAtlas *const atlas) if (image) { +#ifdef USE_SDL2 + SDL_SetSurfaceAlphaMod(image->mSDLSurface, 255); +#else SDL_SetAlpha(image->mSDLSurface, 0, SDL_ALPHA_OPAQUE); +#endif graphics->drawImage(image, item->x, item->y); } } diff --git a/src/resources/image.cpp b/src/resources/image.cpp index c19d92d2d..f6d80e61e 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -245,8 +245,13 @@ void Image::setAlpha(const float alpha) if (!mHasAlphaChannel) { // Set the alpha value this image is drawn at +#ifdef USE_SDL2 + SDL_SetSurfaceAlphaMod(mSDLSurface, + static_cast(255 * mAlpha)); +#else SDL_SetAlpha(mSDLSurface, SDL_SRCALPHA, - static_cast(255 * mAlpha)); + static_cast(255 * mAlpha)); +#endif } else { diff --git a/src/resources/imagehelper.cpp b/src/resources/imagehelper.cpp index 6a4a47505..cdd1672f6 100644 --- a/src/resources/imagehelper.cpp +++ b/src/resources/imagehelper.cpp @@ -62,8 +62,10 @@ SDL_Surface* ImageHelper::convertTo32Bit(SDL_Surface *const tmpImage) return nullptr; SDL_PixelFormat RGBAFormat; RGBAFormat.palette = nullptr; +#ifndef USE_SDL2 RGBAFormat.colorkey = 0; RGBAFormat.alpha = 0; +#endif RGBAFormat.BitsPerPixel = 32; RGBAFormat.BytesPerPixel = 4; #if SDL_BYTEORDER == SDL_BIG_ENDIAN @@ -102,7 +104,9 @@ void ImageHelper::dumpSurfaceFormat(const SDL_Surface *const image) const { const SDL_PixelFormat * const format = image->format; logger->log("Bytes per pixel: %d", format->BytesPerPixel); +#ifndef USE_SDL2 logger->log("Alpha: %d", format->alpha); +#endif logger->log("Loss: %02x, %02x, %02x, %02x", static_cast(format->Rloss), static_cast(format->Gloss), static_cast(format->Bloss), static_cast(format->Aloss)); diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp index 1180135a0..6aed74113 100644 --- a/src/resources/openglimagehelper.cpp +++ b/src/resources/openglimagehelper.cpp @@ -151,8 +151,12 @@ Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage, tmpImage->w, tmpImage->h); } +#ifdef USE_SDL2 + SDL_SetSurfaceAlphaMod(tmpImage, 255); +#else // Make sure the alpha channel is not used, but copied to destination SDL_SetAlpha(tmpImage, 0, SDL_ALPHA_OPAQUE); +#endif // Determine 32-bit masks based on byte order uint32_t rmask, gmask, bmask, amask; diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp index ab0b0663b..8f9d8b396 100644 --- a/src/resources/sdlimagehelper.cpp +++ b/src/resources/sdlimagehelper.cpp @@ -51,8 +51,10 @@ Image *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye) const rgba.palette = nullptr; rgba.BitsPerPixel = 32; rgba.BytesPerPixel = 4; +#ifndef USE_SDL2 rgba.colorkey = 0; rgba.alpha = 255; +#endif #if SDL_BYTEORDER == SDL_BIG_ENDIAN rgba.Rmask = 0x000000FF; @@ -117,6 +119,10 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage, Image *img; bool hasAlpha = false; +#ifdef USE_SDL2 + uint8_t *alphaChannel = nullptr; + SDL_Surface *image = SDLDuplicateSurface(tmpImage); +#else const int sz = tmpImage->w * tmpImage->h; // The alpha channel to be filled with alpha values @@ -170,6 +176,7 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage, delete [] alphaChannel; return nullptr; } +#endif img = new Image(image, hasAlpha, alphaChannel); img->mAlpha = alpha; @@ -190,6 +197,10 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) const return nullptr; bool hasAlpha = false; +#ifdef USE_SDL2 + uint8_t *alphaChannel = nullptr; + SDL_Surface *image = tmpImage; +#else bool converted = false; if (tmpImage->format->BitsPerPixel != 32) @@ -269,7 +280,7 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) const if (converted) SDL_FreeSurface(tmpImage); - +#endif return new Image(image, hasAlpha, alphaChannel); } diff --git a/src/resources/sdlmusic.cpp b/src/resources/sdlmusic.cpp index 5cadbd620..5f18d30d6 100644 --- a/src/resources/sdlmusic.cpp +++ b/src/resources/sdlmusic.cpp @@ -39,7 +39,11 @@ SDLMusic::~SDLMusic() Resource *SDLMusic::load(SDL_RWops *const rw) { +#ifdef USE_SDL2 + if (Mix_Music *const music = Mix_LoadMUS_RW(rw, 1)) +#else if (Mix_Music *const music = Mix_LoadMUS_RW(rw)) +#endif { return new SDLMusic(music); } -- cgit v1.2.3-70-g09d2