Init, errors & main callbacksSDL 3.2

SDL_SetHint

Changes one of SDL's many fine-tuning options, given as a name and a text value.

Signature

bool SDL_SetHint(const char *name, const char *value);

How it works

Hints adjust behaviour that has no function of its own: whether the renderer uses vsync, whether a full-screen window minimizes when it loses focus, which audio driver to try… Each hint has a constant name SDL_HINT_… and takes a string value, often "0" or "1".

Most hints are read when the thing they affect is created, so set them BEFORE SDL_Init, SDL_CreateWindow or SDL_CreateRenderer. Environment variables with the same name win over SDL_SetHint, which lets a user override your choice.

Parameters

nameconst char *

The hint, as an SDL_HINT_… constant.

Common values

SDL_HINT_RENDER_VSYNC
"1": renderers created later sync to the monitor.
SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS
"0": a full-screen window stays visible when you click into the debugger.
SDL_HINT_RENDER_DRIVER
Which renderer backend to prefer, e.g. "vulkan", "opengl", "direct3d11".
SDL_HINT_APP_NAME
Your program's name, shown e.g. in the system's audio mixer.
valueconst char *

The new value as text. SDL copies it.

Return value

true on success, false on failure (see SDL_GetError).

Example

example.cpp
1SDL_SetHint(SDL_HINT_APP_NAME, "Space Miner");
2SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
3SDL_Init(SDL_INIT_VIDEO);
Official SDL wiki