Skip to content

Commit

Permalink
Fix blending errors (original fix by @ekaitz-zarraga)
Browse files Browse the repository at this point in the history
Fixes #320
Fixes #315
  • Loading branch information
Felipe Manga authored and Felipe Manga committed Dec 23, 2023
1 parent bf65b1a commit ec92a86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/she/sdl2/sdl2_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace she {

namespace sdl {
she::SDL2Surface* screen;
she::SDL2Surface* tempSurface;
extern bool isMaximized;
extern bool isMinimized;
std::unordered_map<int, SDL2Display*> windowIdToDisplay;
Expand Down Expand Up @@ -85,6 +86,8 @@ namespace she {
SDL2Display::~SDL2Display()
{
unique_display = NULL;
if (sdl::tempSurface)
sdl::tempSurface->dispose();
if (m_window) {
sdl::windowIdToDisplay.erase(SDL_GetWindowID(m_window));
m_surface->dispose();
Expand Down
17 changes: 15 additions & 2 deletions src/she/sdl2/sdl2_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace she {

namespace sdl {
extern SDL2Surface* screen;
extern SDL2Surface* tempSurface;
}

inline gfx::Color from_sdl(SDL_PixelFormat *format, int color)
Expand Down Expand Up @@ -421,8 +422,20 @@ namespace she {

void SDL2Surface::fillRect(gfx::Color color, const gfx::Rect& rc)
{
SDL_Rect rect{rc.x, rc.y, rc.w, rc.h};
SDL_FillRect(m_bmp, &rect, to_sdl(m_bmp->format, color));
auto alpha = gfx::geta(color);
if (!alpha)
return;
if (alpha != 255) {
if (!sdl::tempSurface)
sdl::tempSurface = new SDL2Surface(1, 1, SDL2Surface::DeleteAndDestroy);
SDL_FillRect(sdl::tempSurface->m_bmp, nullptr, to_sdl(sdl::tempSurface->m_bmp->format, color));
SDL_Rect rect{rc.x, rc.y, rc.w, rc.h};
SDL_Rect srcRect{0, 0, 1, 1};
SDL_BlitScaled(sdl::tempSurface->m_bmp, &srcRect, m_bmp, &rect);
} else {
SDL_Rect rect{rc.x, rc.y, rc.w, rc.h};
SDL_FillRect(m_bmp, &rect, to_sdl(m_bmp->format, color));
}
}

void SDL2Surface::blitTo(Surface* dest, int srcx, int srcy, int dstx, int dsty, int width, int height) const
Expand Down

0 comments on commit ec92a86

Please sign in to comment.