Textures & surfacesSDL 3.2
SDL_SetTextureAlphaMod
Makes a whole texture more transparent when drawn: alpha is multiplied by alpha / 255.
Signature
bool SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha);
How it works
Use it for fades: lower it from 255 to 0 over a second and the sprite disappears smoothly. It only shows if the texture's blend mode uses alpha (SDL_BLENDMODE_BLEND).
Parameters
textureSDL_Texture *
The texture.
alphaUint8
Opacity multiplier, 0 (invisible) to 255 (unchanged).
Return value
true on success, false on failure.
Example
example.cpp
1float t = fadeTime / fadeDuration; // 0 -> 1
2SDL_SetTextureAlphaMod(logo, Uint8(255 * (1.0f - t)));