SDL School

API reference / Windows and drawing

SDL_SetRenderDrawColor

Function, SDL3

Sets the color for the next drawing calls. The color stays until you set another one.

Declaration

#include <SDL3/SDL.h>

bool SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

Parameters

rendererThe renderer.
rThe red part, from 0 to 255.
gThe green part, from 0 to 255.
bThe blue part, from 0 to 255.
aThe alpha part, from 0 to 255. Use SDL_ALPHA_OPAQUE for a solid color.

Return value

True on success. On failure it returns false.

Example

Open a window
SDL_SetRenderDrawColor(renderer, 32, 96, 160, SDL_ALPHA_OPAQUE);

See this code run in Open a window. Download the full program (.zip)

In Draw a rectangle

Draw a rectangle
SDL_SetRenderDrawColor(renderer, 24, 26, 32, SDL_ALPHA_OPAQUE);

See this code run in Draw a rectangle. Download the full program (.zip)

Notes

In SDL2

The name is the same.

See also