Home

SDLTexture

SDLTexture is the SDL library’s abstraction for a 2D image resource that can be rendered using the SDL rendering API. In SDL2, this concept is represented by the SDL_Texture type and is the primary means of displaying pixel data through a renderer. Textures can originate from a system surface or be created from raw pixel data, and they can be classified as static, streaming, or render-target textures depending on how often their contents change and how they are used.

Creation and sources: Textures are created with a renderer, a pixel format, an access mode, and a

Properties and updating data: SDL_QueryTexture retrieves a texture’s format, access, width, and height. Streaming textures can

Rendering: Textures are drawn with SDL_RenderCopy or SDL_RenderCopyEx, using source and destination rectangles, and may be

Memory and lifecycle: Textures typically reside in GPU memory on capable backends, offering efficient rendering. They

width
and
height,
via
a
function
such
as
SDL_CreateTexture.
They
can
also
be
created
from
an
existing
SDL_Surface
using
SDL_CreateTextureFromSurface.
The
access
mode
determines
how
the
texture
will
be
updated:
SDL_TEXTUREACCESS_STATIC
for
rarely
changed
textures,
SDL_TEXTUREACCESS_STREAMING
for
frequently
updated
ones,
and
SDL_TEXTUREACCESS_TARGET
for
render-to-texture
operations.
be
updated
by
locking
the
texture
with
SDL_LockTexture
(which
yields
a
pixel
pointer)
and
then
unlocking
it
with
SDL_UnlockTexture;
updates
can
also
be
performed
with
SDL_UpdateTexture
for
simpler
data
transfers.
rotated
or
flipped.
Texture
state
can
be
adjusted
with
color
modulation
(SDL_SetTextureColorMod),
alpha
modulation
(SDL_SetTextureAlphaMod),
and
blend
mode
(SDL_SetTextureBlendMode).
should
be
destroyed
with
SDL_DestroyTexture
when
no
longer
needed
to
free
resources.