Drawing shapesSDL 3.2

SDL_SetRenderDrawBlendMode

Chooses how shapes drawn with the draw colour mix with what is already there (e.g. transparency).

Signature

bool SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode);

How it works

The default for shapes is SDL_BLENDMODE_NONE: the colour simply replaces the pixels, and alpha is ignored. Switch to SDL_BLENDMODE_BLEND for see-through overlays such as a dark half-transparent box behind a menu.

This only affects rectangles, lines, points and clears. Textures have their own setting, SDL_SetTextureBlendMode.

Parameters

rendererSDL_Renderer *

The renderer.

blendModeSDL_BlendMode

The mixing rule.

Common values

SDL_BLENDMODE_NONE
Replace: dst = src. Default.
SDL_BLENDMODE_BLEND
Transparency: dst = src·a + dst·(1 − a).
SDL_BLENDMODE_ADD
Glow: dst = src·a + dst. Light only gets brighter.
SDL_BLENDMODE_MOD
Tint/darken: dst = src · dst.
SDL_BLENDMODE_BLEND_PREMULTIPLIED
For colours already multiplied by alpha: dst = src + dst·(1 − a).

Return value

true on success, false on failure.

Example

example.cpp
1SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
2SDL_SetRenderDrawColor(renderer, 0, 0, 0, 160);      // 63% black
3SDL_RenderFillRect(renderer, nullptr);               // dim the whole screen
4drawPauseMenu(renderer);
Official SDL wiki