From aa83777c567f9f98aa1cb3cc2708f696001b551f Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 1 Oct 2013 14:26:27 +0200 Subject: [PATCH] Fix color key and alpha blending. --- src/CGraphics.cpp | 19 ++++++++++++------- src/CGraphics.h | 2 ++ src/cutscene.cpp | 6 +++--- src/galdov.cpp | 4 ++-- src/game.cpp | 2 +- src/map.cpp | 2 +- src/mapData.cpp | 2 +- src/mission.cpp | 2 +- src/title.cpp | 12 ++++++------ 9 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/CGraphics.cpp b/src/CGraphics.cpp index 93c2de8..f6e2292 100644 --- a/src/CGraphics.cpp +++ b/src/CGraphics.cpp @@ -20,6 +20,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "headers.h" +void SDL_SetAlpha(SDL_Surface *surface, uint8_t value) { + SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND); + SDL_SetSurfaceAlphaMod(surface, value); +} + Graphics::Graphics() { for (int i = 0 ; i < MAX_TILES ; i++) @@ -154,7 +159,7 @@ Sprite *Graphics::getSpriteHead() void Graphics::setTransparent(SDL_Surface *sprite) { - SDL_SetColorKey(sprite, SDL_RLEACCEL, SDL_MapRGB(sprite->format, 0, 0, 0)); + SDL_SetColorKey(sprite, SDL_TRUE, SDL_MapRGB(sprite->format, 0, 0, 0)); } bool Graphics::canShowMedalMessage() const @@ -370,7 +375,7 @@ SDL_Surface *Graphics::loadImage(const char *filename, bool srcalpha) } if(srcalpha) - SDL_SetSurfaceAlphaMod(newImage, 255); + SDL_SetAlpha(newImage, 255); else setTransparent(newImage); @@ -457,7 +462,7 @@ SDL_Surface *Graphics::quickSprite(const char *name, SDL_Surface *image) void Graphics::fade(int amount) { - SDL_SetSurfaceAlphaMod(fadeBlack, amount); + SDL_SetAlpha(fadeBlack, amount); blit(fadeBlack, 0, 0, screen, false); } @@ -467,7 +472,7 @@ void Graphics::fadeToBlack() while (start < 50) { - SDL_SetSurfaceAlphaMod(fadeBlack, start); + SDL_SetAlpha(fadeBlack, start); blit(fadeBlack, 0, 0, screen, false); delay(60); start++; @@ -519,7 +524,7 @@ void Graphics::loadMapTiles(const char *baseDir) { if ((i < MAP_EXITSIGN) || (i >= MAP_WATERANIM)) { - SDL_SetSurfaceAlphaMod(tile[i], 130); + SDL_SetAlpha(tile[i], 130); } } else @@ -1077,7 +1082,7 @@ SDL_Surface *Graphics::alphaRect(int width, int height, Uint8 red, Uint8 green, SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, red, green, blue)); - SDL_SetSurfaceAlphaMod(surface, 130); + SDL_SetAlpha(surface, 130); return surface; } @@ -1088,7 +1093,7 @@ void Graphics::colorize(SDL_Surface *image, int red, int green, int blue) blit(alpha, 0, 0, image, false); - SDL_SetColorKey(image, SDL_RLEACCEL, SDL_MapRGB(image->format, red / 2, green / 2, blue / 2)); + SDL_SetColorKey(image, SDL_TRUE, SDL_MapRGB(image->format, red / 2, green / 2, blue / 2)); } void Graphics::lock(SDL_Surface *surface) diff --git a/src/CGraphics.h b/src/CGraphics.h index 2070ce5..1f544cf 100644 --- a/src/CGraphics.h +++ b/src/CGraphics.h @@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +void SDL_SetAlpha(SDL_Surface *surface, uint8_t value); + class Graphics { private: diff --git a/src/cutscene.cpp b/src/cutscene.cpp index 75baa4d..4e37d9b 100644 --- a/src/cutscene.cpp +++ b/src/cutscene.cpp @@ -135,7 +135,7 @@ void showScene(bool allowSkip) float panelAlpha = 0; - SDL_SetSurfaceAlphaMod(panel, 0); + SDL_SetAlpha(panel, 0); engine.clearInput(); engine.flushInput(); @@ -164,10 +164,10 @@ void showScene(bool allowSkip) if (panelAlpha < 256) { panelAlpha += (1 * engine.getTimeDifference()); - SDL_SetSurfaceAlphaMod(panel, panelAlpha); + SDL_SetAlpha(panel, panelAlpha); if (image != NULL) { - SDL_SetSurfaceAlphaMod(image, panelAlpha); + SDL_SetAlpha(image, panelAlpha); graphics.blit(image, 0, 0, graphics.screen, false); } graphics.blit(panel, 0, 390, graphics.screen, false); diff --git a/src/galdov.cpp b/src/galdov.cpp index 22f936e..5830916 100644 --- a/src/galdov.cpp +++ b/src/galdov.cpp @@ -474,8 +474,8 @@ void galdovInit() Math::addBit(&map.boss[0]->flags, ENT_AIMS); - SDL_SetSurfaceAlphaMod(graphics.getSprite("GaldovInvsLeft", true)->image[0], 100); - SDL_SetSurfaceAlphaMod(graphics.getSprite("GaldovInvsRight", true)->image[0], 100); + SDL_SetAlpha(graphics.getSprite("GaldovInvsLeft", true)->image[0], 100); + SDL_SetAlpha(graphics.getSprite("GaldovInvsRight", true)->image[0], 100); for (int i = 1 ; i < 10 ; i++) { diff --git a/src/game.cpp b/src/game.cpp index 6f5a970..6ecbfa4 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -381,7 +381,7 @@ void showMissionInformation() SDL_Surface *panel = graphics.createSurface(400, 300); SDL_Surface *panelBack = graphics.alphaRect(400, 300, 0x00, 0x00, 0x00); - SDL_SetColorKey(panel, SDL_RLEACCEL, SDL_MapRGB(panel->format, 0, 0, 0)); + SDL_SetColorKey(panel, SDL_TRUE, SDL_MapRGB(panel->format, 0, 0, 0)); graphics.drawRect(1, 1, 398, 298, graphics.black, graphics.white, panelBack); diff --git a/src/map.cpp b/src/map.cpp index 07eb4aa..378c888 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -293,7 +293,7 @@ void showMap(int centerX, int centerY) SDL_Surface *panel = graphics.createSurface(320, 240); SDL_Surface *background = graphics.loadImage("gfx/main/mapBackground.png"); - SDL_SetSurfaceAlphaMod(background, 130); + SDL_SetAlpha(background, 130); graphics.blit(background, 0, 0, panel, false); diff --git a/src/mapData.cpp b/src/mapData.cpp index a617a02..fb64299 100644 --- a/src/mapData.cpp +++ b/src/mapData.cpp @@ -284,7 +284,7 @@ void getMapTokens() debug(("Setting Alpha for Tile %d\n", param[0])); - SDL_SetSurfaceAlphaMod(graphics.tile[param[0]], 130); + SDL_SetAlpha(graphics.tile[param[0]], 130); while (true) { diff --git a/src/mission.cpp b/src/mission.cpp index 983b47b..6321a55 100644 --- a/src/mission.cpp +++ b/src/mission.cpp @@ -162,7 +162,7 @@ void showMissionClear() graphics.loadBackground("gfx/main/areaClearBackGround.jpg"); SDL_Surface *panel = graphics.alphaRect(550, 420, 0x00, 0x00, 0x00); - SDL_SetSurfaceAlphaMod(panel, 180); + SDL_SetAlpha(panel, 180); graphics.drawRect(1, 1, panel->w - 2, panel->h - 2 , graphics.black, graphics.white, panel); graphics.blit(panel, (640 - panel->w) / 2, (480 - panel->h) / 2, graphics.background, false); diff --git a/src/title.cpp b/src/title.cpp index 7b5e050..9143955 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -197,12 +197,12 @@ int title() snprintf(v, sizeof v, _("Version %s"), STRINGIFY_VALUE(VERSION)); SDL_Surface *version = graphics.quickSprite("Version", graphics.getString(v, true)); - SDL_SetSurfaceAlphaMod(title, 0); + SDL_SetAlpha(title, 0); audio.loadMusic("music/title"); graphics.loadBackground("gfx/main/CircuitBoard.jpg"); - SDL_SetSurfaceAlphaMod(graphics.background, 0); + SDL_SetAlpha(graphics.background, 0); int startNewGame, options, quit, help, easy, normal, hard, extreme, back, practice; int load, cont, save[5], slot[6]; @@ -268,8 +268,8 @@ int title() engine.clearInput(); backAlpha = 255; titleAlpha = 255; - SDL_SetSurfaceAlphaMod(graphics.background, backAlpha); - SDL_SetSurfaceAlphaMod(title, titleAlpha); + SDL_SetAlpha(graphics.background, backAlpha); + SDL_SetAlpha(title, titleAlpha); } } @@ -278,7 +278,7 @@ int title() if (backAlpha < 255) { backAlpha++; - SDL_SetSurfaceAlphaMod(graphics.background, backAlpha); + SDL_SetAlpha(graphics.background, backAlpha); } } @@ -287,7 +287,7 @@ int title() if (titleAlpha < 255) { titleAlpha++; - SDL_SetSurfaceAlphaMod(title, titleAlpha); + SDL_SetAlpha(title, titleAlpha); } else { -- 2.39.5