SDL School

API reference / Images and textures

SDL_GetTextureSize

Function, SDL3

Gets the size of a texture in pixels.

Declaration

#include <SDL3/SDL.h>

bool SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h);

Parameters

textureThe texture.
wThe address of a float for the width, or NULL.
hThe address of a float for the height, or NULL.

Return value

True on success. On failure it returns false.

Example

Load an image
SDL_GetTextureSize(ship, &width, &height);

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

In SDL2

Use SDL_QueryTexture, which gives int values.

See also