SDL School

API reference / Images and textures

SDL_RenderTexture

Function, SDL3

Draws a texture, or a part of it, at a position and size.

Declaration

#include <SDL3/SDL.h>

bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect);

Parameters

rendererThe renderer.
textureThe texture.
srcrectThe part of the texture to use, or NULL for all of it.
dstrectThe place on the window, or NULL for the full window.

Return value

True on success. On failure it returns false.

Example

Load an image
SDL_SetRenderDrawColor(renderer, 32, 96, 160, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer);

SDL_RenderTexture(renderer, ship, NULL, &small);

See this code run in Load an image. Download the full program (.zip)

In SDL2

Use SDL_RenderCopyF. Its source rectangle is an SDL_Rect.

See also