From 14017144621d5599e8eb920e7e8315b19a607917 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 5 Sep 2020 12:39:16 +0200 Subject: [PATCH] Properly implement the blending --- src/gui/GuiText.cpp | 5 ++++- src/gui/GuiTextureData.cpp | 21 ++++++++++++++++----- src/gui/GuiTextureData.h | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/gui/GuiText.cpp b/src/gui/GuiText.cpp index 0873a43..7caa8a0 100644 --- a/src/gui/GuiText.cpp +++ b/src/gui/GuiText.cpp @@ -76,7 +76,10 @@ void GuiText::updateTexture(Renderer *renderer) { textureData->setBlendMode(SDL_BLENDMODE_BLEND); texture.setTexture(textureData); - FC_DrawColumnToTexture(fc_font, temp, 0, 0, maxWidth, text.c_str()); + SDL_SetRenderTarget(renderer->getRenderer(), temp); + SDL_RenderClear(renderer->getRenderer()); + FC_DrawColumn(fc_font, renderer->getRenderer(), 0, 0, maxWidth, text.c_str()); + SDL_SetRenderTarget(renderer->getRenderer(), NULL); } else { DEBUG_FUNCTION_LINE("Failed to create texture"); } diff --git a/src/gui/GuiTextureData.cpp b/src/gui/GuiTextureData.cpp index d93f14f..7885583 100644 --- a/src/gui/GuiTextureData.cpp +++ b/src/gui/GuiTextureData.cpp @@ -24,11 +24,8 @@ GuiTextureData::GuiTextureData(SDL_Texture *texture) { SDL_QueryTexture(this->texture, nullptr, nullptr, &w, &h); this->width = w; this->height = h; - } - - void GuiTextureData::loadSurface(SDL_Surface *pSurface) { if(!pSurface){ return; @@ -74,14 +71,28 @@ void GuiTextureData::draw(Renderer *renderer, const SDL_Rect& dest, float angle) return; } + // copy the texture to the rendering context + SDL_BlendMode mode; + SDL_GetRenderDrawBlendMode(renderer->getRenderer(), &mode); + + // adjust blend mode + if(blendMode != mode){ + SDL_SetRenderDrawBlendMode(renderer->getRenderer(), blendMode); + } + if (angle == 0) { SDL_RenderCopy(renderer->getRenderer(), texture, nullptr, &dest); } else { SDL_RenderCopyEx(renderer->getRenderer(), texture, nullptr, &dest, angle, nullptr, SDL_FLIP_NONE); } + + if(blendMode != mode){ + SDL_SetRenderDrawBlendMode(renderer->getRenderer(), mode); + } } -int GuiTextureData::setBlendMode(SDL_BlendMode) { - if(texture){ return SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); } +int GuiTextureData::setBlendMode(SDL_BlendMode blendMode) { + this->blendMode = blendMode; + if(texture){ return SDL_SetTextureBlendMode(texture, blendMode); } return SDL_BLENDMODE_INVALID; } \ No newline at end of file diff --git a/src/gui/GuiTextureData.h b/src/gui/GuiTextureData.h index 3f11b24..c081854 100644 --- a/src/gui/GuiTextureData.h +++ b/src/gui/GuiTextureData.h @@ -37,4 +37,5 @@ protected: SDL_Texture *texture = nullptr; int32_t width = 0; int32_t height = 0; + SDL_BlendMode blendMode; };