Clear texture after creation, fix blendMode of GuiTexture.

This commit is contained in:
Maschell 2020-08-30 23:23:28 +02:00
parent 65bbe1f82f
commit 16862f2a88
3 changed files with 11 additions and 21 deletions

View File

@ -65,11 +65,12 @@ void GuiText::draw(CVideo *pVideo) {
if(temp){ if(temp){
texture = new GuiTexture(temp); texture = new GuiTexture(temp);
texture->setParent(this); texture->setParent(this);
texture->setBlend(SDL_BLENDMODE_BLEND); texture->setBlendMode(SDL_BLENDMODE_BLEND);
// Draw the text onto it // Draw the text onto it
SDL_SetRenderTarget(pVideo->getRenderer(), temp); SDL_SetRenderTarget(pVideo->getRenderer(), temp);
SDL_SetTextureBlendMode(temp, SDL_BLENDMODE_BLEND); // make sure the texture is clean.
SDL_RenderClear(pVideo->getRenderer());
FC_DrawColumn(fc_font, pVideo->getRenderer(), 0, 0, maxWidth, text.c_str()); FC_DrawColumn(fc_font, pVideo->getRenderer(), 0, 0, maxWidth, text.c_str());
SDL_SetRenderTarget(pVideo->getRenderer(), NULL); SDL_SetRenderTarget(pVideo->getRenderer(), NULL);

View File

@ -78,26 +78,16 @@ void GuiTexture::draw(CVideo *pVideo) {
rect.w = currScaleX * getWidth(); rect.w = currScaleX * getWidth();
rect.h = currScaleY * getHeight(); rect.h = currScaleY * getHeight();
// copy the texture to the rendering context
SDL_BlendMode mode;
SDL_GetRenderDrawBlendMode(pVideo->getRenderer(), &mode);
// adjust blend mode
if(blendMode != mode){
SDL_SetRenderDrawBlendMode(pVideo->getRenderer(), blendMode);
}
if (getAngle() == 0) { if (getAngle() == 0) {
SDL_RenderCopy(pVideo->getRenderer(), texture, NULL, &rect); SDL_RenderCopy(pVideo->getRenderer(), texture, nullptr, &rect);
} else { } else {
SDL_RenderCopyEx(pVideo->getRenderer(), texture, NULL, &rect, getAngle(), NULL, SDL_FLIP_NONE); SDL_RenderCopyEx(pVideo->getRenderer(), texture, nullptr, &rect, getAngle(), nullptr, SDL_FLIP_NONE);
}
// Restore blend mode
if(blendMode != mode) {
SDL_SetRenderDrawBlendMode(pVideo->getRenderer(), mode);
} }
} }
void GuiTexture::setBlend(SDL_BlendMode blendmode) { int GuiTexture::setBlendMode(SDL_BlendMode) {
this->blendMode = blendMode; if(texture){
return SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
}
return SDL_BLENDMODE_INVALID;
} }

View File

@ -14,10 +14,9 @@ public:
//!Constantly called to draw the image //!Constantly called to draw the image
void draw(CVideo *pVideo) override; void draw(CVideo *pVideo) override;
void setBlend(SDL_BlendMode blendMode); int setBlendMode(SDL_BlendMode blendMode);
protected: protected:
SDL_Surface *imgSurface = nullptr; SDL_Surface *imgSurface = nullptr;
SDL_Texture *texture = nullptr; SDL_Texture *texture = nullptr;
SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
}; };