2D rendererSDL 3.2

SDL_CreateRenderer

Creates a 2D renderer for a window: the object that draws rectangles, lines and textures with the GPU.

Signature

SDL_Renderer * SDL_CreateRenderer(SDL_Window *window, const char *name);

How it works

The renderer is SDL's simple 2D API. Under the hood it uses whatever the platform does best (Direct3D, Metal, Vulkan, OpenGL), but you only see functions like SDL_RenderTexture. Pass NULL as the name and SDL picks the best driver.

Every texture belongs to the renderer that created it: you cannot draw a texture of renderer A with renderer B.

Parameters

windowSDL_Window *

The window to draw into.

nameconst char *

NULL for the best driver, or one name such as "direct3d11", "metal", "vulkan", "opengl", "gpu", "software".

Return value

The renderer, or NULL on failure.

Tips & pitfalls

Example

example.cpp
1SDL_Renderer* renderer = SDL_CreateRenderer(window, nullptr);
2if (!renderer) { SDL_Log("CreateRenderer: %s", SDL_GetError()); return 1; }
3SDL_SetRenderVSync(renderer, 1);
4SDL_Log("renderer: %s", SDL_GetRendererName(renderer));
Official SDL wiki