mirror of
https://github.com/Maschell/SDL2_Playground.git
synced 2024-11-14 17:15:06 +01:00
Properly implement the blending
This commit is contained in:
parent
693c3184c3
commit
1401714462
@ -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");
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -37,4 +37,5 @@ protected:
|
||||
SDL_Texture *texture = nullptr;
|
||||
int32_t width = 0;
|
||||
int32_t height = 0;
|
||||
SDL_BlendMode blendMode;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user