Textures & surfacesSDL 3.2

SDL_SetTextureColorMod

Tints a texture: every pixel's colour is multiplied by (r, g, b) / 255 when drawn.

Signature

bool SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b);

How it works

The formula is srcC = srcC · (color / 255) for each channel. White (255, 255, 255) leaves the texture unchanged; (255, 128, 128) keeps red and halves green and blue, a red flash for "took damage". The texture's pixels are not changed: it is applied at draw time, so you can change it every frame.

Parameters

textureSDL_Texture *

The texture.

rUint8

Red multiplier, 0–255.

gUint8

Green multiplier, 0–255.

bUint8

Blue multiplier, 0–255.

Return value

true on success; false if the renderer cannot do it.

Example

example.cpp
1if (enemy.hitTimer > 0) SDL_SetTextureColorMod(enemyTex, 255, 128, 128);
2else                    SDL_SetTextureColorMod(enemyTex, 255, 255, 255);
3SDL_RenderTexture(renderer, enemyTex, nullptr, &enemy.rect);
Official SDL wiki