Textures & surfacesSDL 3.2
SDL_RenderTexture
Draws a texture, or part of it, into a rectangle on screen. The sprite-drawing call (SDL_RenderCopy in SDL2).
Signature
bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect);
How it works
srcrect picks which part of the texture to use: NULL for all of it, or one frame of a sprite sheet. dstrect says where it goes and how big: NULL stretches over the whole target. If the sizes differ, the image is scaled using the texture's scale mode.
Parameters
rendererSDL_Renderer *
The renderer.
textureSDL_Texture *
The texture to draw (created by this renderer).
srcrectconst SDL_FRect *
Part of the texture in texture pixels, or NULL for all.
dstrectconst SDL_FRect *
Where to draw, or NULL for the whole target.
Return value
true on success, false on failure.
Example
example.cpp
1// frame 3 of a sheet of 32x32 frames in one row
2SDL_FRect src{3 * 32.0f, 0.0f, 32.0f, 32.0f};
3SDL_FRect dst{player.x, player.y, 64.0f, 64.0f}; // drawn at 2x
4SDL_RenderTexture(renderer, sheet, &src, &dst);