0

I have this PNG file that has a transparent background. Snippet of transparent background

I set it to surface then to tex :

SDL_Texture* m_Tex = SDL_CreateTextureFromSurface(renderer, surface);

And I want this texture to have a blinking effect so I'm passing it to setTextureBlendMode function

SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
Uint8 m_Alpha = 255;

I will use the m_Alpha for the blinking purpose. I will activate the blinking by pressing a particular button. And it is working fine. But Why is the background of my texture not transparent anymore after I turn it back to SDL_BLENDMODE_NONE:

SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_NONE);

Snippet of not transparent anymore after BLENDMODE_NONE

Is there a way to make my texture's background transparent again? I mean, after researching enough, I can't seem to find a way except the SDL_SetColorKey. But the SDL_SetColorKey needs the loaded surface again. It only means that I will set the PNG file again on surface, then on tex. I think it's not ideal to do this everytime I want the tex to stop blinking. Please help. Thanks.

1 Answers1

0

SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_NONE); To render textures with Alpha != 1, you will need some blend mode.

In blend mode, you are describing to the system How you want to merge the background color with the foreground color.

You can have a basic idea from this thread. SDL2: Generate fully transparent texture

Mubashar M
  • 68
  • 5