mirror of
https://github.com/Maschell/SDL2_Playground.git
synced 2025-01-27 12:15:38 +01:00
Clear texture after creation, fix blendMode of GuiTexture.
This commit is contained in:
parent
65bbe1f82f
commit
16862f2a88
@ -65,11 +65,12 @@ void GuiText::draw(CVideo *pVideo) {
|
||||
if(temp){
|
||||
texture = new GuiTexture(temp);
|
||||
texture->setParent(this);
|
||||
texture->setBlend(SDL_BLENDMODE_BLEND);
|
||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Draw the text onto it
|
||||
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());
|
||||
SDL_SetRenderTarget(pVideo->getRenderer(), NULL);
|
||||
|
||||
|
@ -78,26 +78,16 @@ void GuiTexture::draw(CVideo *pVideo) {
|
||||
rect.w = currScaleX * getWidth();
|
||||
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) {
|
||||
SDL_RenderCopy(pVideo->getRenderer(), texture, NULL, &rect);
|
||||
SDL_RenderCopy(pVideo->getRenderer(), texture, nullptr, &rect);
|
||||
} else {
|
||||
SDL_RenderCopyEx(pVideo->getRenderer(), texture, NULL, &rect, getAngle(), NULL, SDL_FLIP_NONE);
|
||||
}
|
||||
// Restore blend mode
|
||||
if(blendMode != mode) {
|
||||
SDL_SetRenderDrawBlendMode(pVideo->getRenderer(), mode);
|
||||
SDL_RenderCopyEx(pVideo->getRenderer(), texture, nullptr, &rect, getAngle(), nullptr, SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiTexture::setBlend(SDL_BlendMode blendmode) {
|
||||
this->blendMode = blendMode;
|
||||
int GuiTexture::setBlendMode(SDL_BlendMode) {
|
||||
if(texture){
|
||||
return SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
return SDL_BLENDMODE_INVALID;
|
||||
}
|
||||
|
||||
|
@ -14,10 +14,9 @@ public:
|
||||
//!Constantly called to draw the image
|
||||
void draw(CVideo *pVideo) override;
|
||||
|
||||
void setBlend(SDL_BlendMode blendMode);
|
||||
int setBlendMode(SDL_BlendMode blendMode);
|
||||
|
||||
protected:
|
||||
SDL_Surface *imgSurface = nullptr;
|
||||
SDL_Texture *texture = nullptr;
|
||||
SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user