SDL School

API reference / Images and textures

SDL_RenderTextureRotated

Function, SDL3

Draws a texture with a rotation, a flip, or both.

Declaration

#include <SDL3/SDL.h>

bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect, double angle, const SDL_FPoint *center, SDL_FlipMode flip);

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.
angleThe rotation in degrees, clockwise.
centerThe point to rotate around, or NULL for the center.
flipSDL_FLIP_NONE, SDL_FLIP_HORIZONTAL, or SDL_FLIP_VERTICAL.

Return value

True on success. On failure it returns false.

Example

Sprites and animation
SDL_FRect source = { (float)current_frame * SPRITE_SIZE, 0.0f, SPRITE_SIZE, SPRITE_SIZE };
SDL_FRect destination = { robot_x, 240.0f, DRAW_SIZE, DRAW_SIZE };
SDL_FlipMode flip = (direction < 0.0f) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;

SDL_RenderTextureRotated(renderer, sheet, &source, &destination, 0.0, NULL, flip);

See this code run in Sprites and animation. Download the full program (.zip)

In SDL2

Use SDL_RenderCopyExF.

See also