summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/atlasmanager.cpp4
-rw-r--r--src/resources/image.cpp7
-rw-r--r--src/resources/imagehelper.cpp4
-rw-r--r--src/resources/openglimagehelper.cpp4
-rw-r--r--src/resources/sdlimagehelper.cpp13
-rw-r--r--src/resources/sdlmusic.cpp4
6 files changed, 34 insertions, 2 deletions
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<unsigned char>(255 * mAlpha));
+#else
SDL_SetAlpha(mSDLSurface, SDL_SRCALPHA,
- static_cast<unsigned char>(255 * mAlpha));
+ static_cast<unsigned char>(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<int>(format->Rloss), static_cast<int>(format->Gloss),
static_cast<int>(format->Bloss), static_cast<int>(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);
}