Textures & surfacesSDL 3.2

SDL_CreateTexture

Creates an empty texture: to draw into (target) or to fill with your own pixels every frame (streaming).

Signature

SDL_Texture * SDL_CreateTexture(SDL_Renderer *renderer, SDL_PixelFormat format, SDL_TextureAccess access, int w, int h);

How it works

The access mode decides what you can do with it. STATIC is for images that never change (that is what SDL_CreateTextureFromSurface makes). STREAMING lets you write pixels from the CPU with SDL_LockTexture: emulators, video, software renderers. TARGET lets the renderer draw into it with SDL_SetRenderTarget: minimaps, low-resolution game screens, cached backgrounds.

Parameters

rendererSDL_Renderer *

The renderer that will own the texture.

formatSDL_PixelFormat

The pixel layout.

Common values

SDL_PIXELFORMAT_RGBA32
Bytes R, G, B, A in memory order on any machine. Easiest to fill by hand.
SDL_PIXELFORMAT_RGBA8888 / ARGB8888
One Uint32 per pixel, channels packed from the high bits down.
accessSDL_TextureAccess

How the texture will be used.

Common values

SDL_TEXTUREACCESS_STATIC
Rarely changes (SDL_UpdateTexture to change it).
SDL_TEXTUREACCESS_STREAMING
Rewritten often with SDL_LockTexture.
SDL_TEXTUREACCESS_TARGET
Can be a render target.
wint

Width in pixels.

hint

Height in pixels.

Return value

The texture, or NULL on failure.

Example

example.cpp
1SDL_Texture* screen = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32,
2                                       SDL_TEXTUREACCESS_STREAMING, 320, 240);
3SDL_SetTextureScaleMode(screen, SDL_SCALEMODE_NEAREST);
Official SDL wiki