SDL  2.0
SDL_render.h File Reference
#include "SDL_stdinc.h"
#include "SDL_rect.h"
#include "SDL_video.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_render.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_RendererInfo
 Information on the capabilities of a render driver or context. More...

Enumerations

enum  SDL_RendererFlags {
  SDL_RENDERER_SOFTWARE = 0x00000001,
  SDL_RENDERER_ACCELERATED = 0x00000002,
  SDL_RENDERER_PRESENTVSYNC = 0x00000004,
  SDL_RENDERER_TARGETTEXTURE = 0x00000008
}
 Flags used when creating a rendering context. More...
enum  SDL_TextureAccess {
  SDL_TEXTUREACCESS_STATIC,
  SDL_TEXTUREACCESS_STREAMING,
  SDL_TEXTUREACCESS_TARGET
}
 The access pattern allowed for a texture. More...
enum  SDL_TextureModulate {
  SDL_TEXTUREMODULATE_NONE = 0x00000000,
  SDL_TEXTUREMODULATE_COLOR = 0x00000001,
  SDL_TEXTUREMODULATE_ALPHA = 0x00000002
}
 The texture channel modulation used in SDL_RenderCopy(). More...
enum  SDL_RendererFlip {
  SDL_FLIP_NONE = 0x00000000,
  SDL_FLIP_HORIZONTAL = 0x00000001,
  SDL_FLIP_VERTICAL = 0x00000002
}
 Flip constants for SDL_RenderCopyEx. More...

Functions

int SDL_GetNumRenderDrivers (void)
 Get the number of 2D rendering drivers available for the current display.
int SDL_GetRenderDriverInfo (int index, SDL_RendererInfo *info)
 Get information about a specific 2D rendering driver for the current display.
int SDL_CreateWindowAndRenderer (int width, int height, Uint32 window_flags, SDL_Window **window, SDL_Renderer **renderer)
 Create a window and default renderer.
SDL_RendererSDL_CreateRenderer (SDL_Window *window, int index, Uint32 flags)
 Create a 2D rendering context for a window.
SDL_RendererSDL_CreateSoftwareRenderer (SDL_Surface *surface)
 Create a 2D software rendering context for a surface.
SDL_RendererSDL_GetRenderer (SDL_Window *window)
 Get the renderer associated with a window.
int SDL_GetRendererInfo (SDL_Renderer *renderer, SDL_RendererInfo *info)
 Get information about a rendering context.
int SDL_GetRendererOutputSize (SDL_Renderer *renderer, int *w, int *h)
 Get the output size in pixels of a rendering context.
SDL_TextureSDL_CreateTexture (SDL_Renderer *renderer, Uint32 format, int access, int w, int h)
 Create a texture for a rendering context.
SDL_TextureSDL_CreateTextureFromSurface (SDL_Renderer *renderer, SDL_Surface *surface)
 Create a texture from an existing surface.
int SDL_QueryTexture (SDL_Texture *texture, Uint32 *format, int *access, int *w, int *h)
 Query the attributes of a texture.
int SDL_SetTextureColorMod (SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b)
 Set an additional color value used in render copy operations.
int SDL_GetTextureColorMod (SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b)
 Get the additional color value used in render copy operations.
int SDL_SetTextureAlphaMod (SDL_Texture *texture, Uint8 alpha)
 Set an additional alpha value used in render copy operations.
int SDL_GetTextureAlphaMod (SDL_Texture *texture, Uint8 *alpha)
 Get the additional alpha value used in render copy operations.
int SDL_SetTextureBlendMode (SDL_Texture *texture, SDL_BlendMode blendMode)
 Set the blend mode used for texture copy operations.
int SDL_GetTextureBlendMode (SDL_Texture *texture, SDL_BlendMode *blendMode)
 Get the blend mode used for texture copy operations.
int SDL_UpdateTexture (SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
 Update the given texture rectangle with new pixel data.
int SDL_UpdateYUVTexture (SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch)
 Update a rectangle within a planar YV12 or IYUV texture with new pixel data.
int SDL_LockTexture (SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
 Lock a portion of the texture for write-only pixel access.
void SDL_UnlockTexture (SDL_Texture *texture)
 Unlock a texture, uploading the changes to video memory, if needed.
SDL_bool SDL_RenderTargetSupported (SDL_Renderer *renderer)
 Determines whether a window supports the use of render targets.
int SDL_SetRenderTarget (SDL_Renderer *renderer, SDL_Texture *texture)
 Set a texture as the current rendering target.
SDL_TextureSDL_GetRenderTarget (SDL_Renderer *renderer)
 Get the current render target or NULL for the default render target.
int SDL_RenderSetLogicalSize (SDL_Renderer *renderer, int w, int h)
 Set device independent resolution for rendering.
void SDL_RenderGetLogicalSize (SDL_Renderer *renderer, int *w, int *h)
 Get device independent resolution for rendering.
int SDL_RenderSetIntegerScale (SDL_Renderer *renderer, SDL_bool enable)
 Set whether to force integer scales for resolution-independent rendering.
SDL_bool SDL_RenderGetIntegerScale (SDL_Renderer *renderer)
 Get whether integer scales are forced for resolution-independent rendering.
int SDL_RenderSetViewport (SDL_Renderer *renderer, const SDL_Rect *rect)
 Set the drawing area for rendering on the current target.
void SDL_RenderGetViewport (SDL_Renderer *renderer, SDL_Rect *rect)
 Get the drawing area for the current target.
int SDL_RenderSetClipRect (SDL_Renderer *renderer, const SDL_Rect *rect)
 Set the clip rectangle for the current target.
void SDL_RenderGetClipRect (SDL_Renderer *renderer, SDL_Rect *rect)
 Get the clip rectangle for the current target.
SDL_bool SDL_RenderIsClipEnabled (SDL_Renderer *renderer)
 Get whether clipping is enabled on the given renderer.
int SDL_RenderSetScale (SDL_Renderer *renderer, float scaleX, float scaleY)
 Set the drawing scale for rendering on the current target.
void SDL_RenderGetScale (SDL_Renderer *renderer, float *scaleX, float *scaleY)
 Get the drawing scale for the current target.
int SDL_SetRenderDrawColor (SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 Set the color used for drawing operations (Rect, Line and Clear).
int SDL_GetRenderDrawColor (SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
 Get the color used for drawing operations (Rect, Line and Clear).
int SDL_SetRenderDrawBlendMode (SDL_Renderer *renderer, SDL_BlendMode blendMode)
 Set the blend mode used for drawing operations (Fill and Line).
int SDL_GetRenderDrawBlendMode (SDL_Renderer *renderer, SDL_BlendMode *blendMode)
 Get the blend mode used for drawing operations.
int SDL_RenderClear (SDL_Renderer *renderer)
 Clear the current rendering target with the drawing color.
int SDL_RenderDrawPoint (SDL_Renderer *renderer, int x, int y)
 Draw a point on the current rendering target.
int SDL_RenderDrawPoints (SDL_Renderer *renderer, const SDL_Point *points, int count)
 Draw multiple points on the current rendering target.
int SDL_RenderDrawLine (SDL_Renderer *renderer, int x1, int y1, int x2, int y2)
 Draw a line on the current rendering target.
int SDL_RenderDrawLines (SDL_Renderer *renderer, const SDL_Point *points, int count)
 Draw a series of connected lines on the current rendering target.
int SDL_RenderDrawRect (SDL_Renderer *renderer, const SDL_Rect *rect)
 Draw a rectangle on the current rendering target.
int SDL_RenderDrawRects (SDL_Renderer *renderer, const SDL_Rect *rects, int count)
 Draw some number of rectangles on the current rendering target.
int SDL_RenderFillRect (SDL_Renderer *renderer, const SDL_Rect *rect)
 Fill a rectangle on the current rendering target with the drawing color.
int SDL_RenderFillRects (SDL_Renderer *renderer, const SDL_Rect *rects, int count)
 Fill some number of rectangles on the current rendering target with the drawing color.
int SDL_RenderCopy (SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect)
 Copy a portion of the texture to the current rendering target.
int SDL_RenderCopyEx (SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect, const double angle, const SDL_Point *center, const SDL_RendererFlip flip)
 Copy a portion of the source texture to the current rendering target, rotating it by angle around the given center.
int SDL_RenderReadPixels (SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
 Read pixels from the current rendering target.
void SDL_RenderPresent (SDL_Renderer *renderer)
 Update the screen with rendering performed.
void SDL_DestroyTexture (SDL_Texture *texture)
 Destroy the specified texture.
void SDL_DestroyRenderer (SDL_Renderer *renderer)
 Destroy the rendering context for a window and free associated textures.
int SDL_GL_BindTexture (SDL_Texture *texture, float *texw, float *texh)
 Bind the texture to the current OpenGL/ES/ES2 context for use with OpenGL instructions.
int SDL_GL_UnbindTexture (SDL_Texture *texture)
 Unbind a texture from the current OpenGL/ES/ES2 context.
voidSDL_RenderGetMetalLayer (SDL_Renderer *renderer)
 Get the CAMetalLayer associated with the given Metal renderer.
voidSDL_RenderGetMetalCommandEncoder (SDL_Renderer *renderer)
 Get the Metal command encoder for the current frame.

Detailed Description

Header file for SDL 2D rendering functions.

This API supports the following features:

  • single pixel points
  • single pixel lines
  • filled rectangles
  • texture images

The primitives may be drawn in opaque, blended, or additive modes.

The texture images may be drawn in opaque, blended, or additive modes. They can have an additional color tint or alpha modulation applied to them, and may also be stretched with linear interpolation.

This API is designed to accelerate simple 2D operations. You may want more functionality such as polygons and particle effects and in that case you should use SDL's OpenGL/Direct3D support or one of the many good 3D engines.

These functions must be called from the main thread. See this bug for details: http://bugzilla.libsdl.org/show_bug.cgi?id=1995

Definition in file SDL_render.h.

Enumeration Type Documentation

Flags used when creating a rendering context.

Enumerator:
SDL_RENDERER_SOFTWARE 

The renderer is a software fallback

SDL_RENDERER_ACCELERATED 

The renderer uses hardware acceleration

SDL_RENDERER_PRESENTVSYNC 

Present is synchronized with the refresh rate

SDL_RENDERER_TARGETTEXTURE 

The renderer supports rendering to texture

Definition at line 64 of file SDL_render.h.

{
SDL_RENDERER_SOFTWARE = 0x00000001, /**< The renderer is a software fallback */
SDL_RENDERER_ACCELERATED = 0x00000002, /**< The renderer uses hardware
acceleration */
SDL_RENDERER_PRESENTVSYNC = 0x00000004, /**< Present is synchronized
with the refresh rate */
SDL_RENDERER_TARGETTEXTURE = 0x00000008 /**< The renderer supports
rendering to texture */

Flip constants for SDL_RenderCopyEx.

Enumerator:
SDL_FLIP_NONE 

Do not flip

SDL_FLIP_HORIZONTAL 

flip horizontally

SDL_FLIP_VERTICAL 

flip vertically

Definition at line 111 of file SDL_render.h.

{
SDL_FLIP_NONE = 0x00000000, /**< Do not flip */
SDL_FLIP_HORIZONTAL = 0x00000001, /**< flip horizontally */
SDL_FLIP_VERTICAL = 0x00000002 /**< flip vertically */

The access pattern allowed for a texture.

Enumerator:
SDL_TEXTUREACCESS_STATIC 

Changes rarely, not lockable

SDL_TEXTUREACCESS_STREAMING 

Changes frequently, lockable

SDL_TEXTUREACCESS_TARGET 

Texture can be used as a render target

Definition at line 91 of file SDL_render.h.

{
SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
SDL_TEXTUREACCESS_STREAMING, /**< Changes frequently, lockable */
SDL_TEXTUREACCESS_TARGET /**< Texture can be used as a render target */

The texture channel modulation used in SDL_RenderCopy().

Enumerator:
SDL_TEXTUREMODULATE_NONE 

No modulation

SDL_TEXTUREMODULATE_COLOR 

srcC = srcC * color

SDL_TEXTUREMODULATE_ALPHA 

srcA = srcA * alpha

Definition at line 101 of file SDL_render.h.

{
SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */
SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */
SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */

Function Documentation

SDL_Renderer* SDL_CreateRenderer ( SDL_Window window,
int  index,
Uint32  flags 
)

Create a 2D rendering context for a window.

Parameters
windowThe window where rendering is displayed.
indexThe index of the rendering driver to initialize, or -1 to initialize the first one supporting the requested flags.
flagsSDL_RendererFlags.
Returns
A valid rendering context or NULL if there was an error.
See Also
SDL_CreateSoftwareRenderer()
SDL_GetRendererInfo()
SDL_DestroyRenderer()

Definition at line 304 of file SDL_render.c.

References SDL_RenderDriver::CreateRenderer, SDL_Renderer::dpi_scale, SDL_RendererInfo::flags, SDL_Renderer::GetOutputSize, SDL_Renderer::hidden, SDL_Renderer::info, SDL_RenderDriver::info, SDL_Renderer::magic, SDL_RendererInfo::name, NULL, renderer, renderer_magic, SDL_Renderer::scale, SDL_AddEventWatch, SDL_CreateMutex, SDL_FALSE, SDL_GetHint, SDL_GetHintBoolean, SDL_GetNumRenderDrivers, SDL_GetRenderer, SDL_GetWindowFlags, SDL_GetWindowSize, SDL_HINT_RENDER_DRIVER, SDL_HINT_RENDER_VSYNC, SDL_LOG_CATEGORY_RENDER, SDL_LogInfo, SDL_RENDERER_PRESENTVSYNC, SDL_RendererEventWatch(), SDL_RenderSetViewport, SDL_SetError, SDL_SetWindowData, SDL_strcasecmp, SDL_TRUE, SDL_WINDOW_HIDDEN, SDL_WINDOW_MINIMIZED, SDL_WINDOWRENDERDATA, SDL_Renderer::target_mutex, SDL_Renderer::window, window_h, window_w, SDL_FPoint::x, and SDL_FPoint::y.

{
#if !SDL_RENDER_DISABLED
const char *hint;
if (!window) {
SDL_SetError("Invalid window");
return NULL;
}
if (SDL_GetRenderer(window)) {
SDL_SetError("Renderer already associated with window");
return NULL;
}
} else {
}
}
if (index < 0) {
if (hint) {
for (index = 0; index < n; ++index) {
if (SDL_strcasecmp(hint, driver->info.name) == 0) {
/* Create a new renderer instance */
renderer = driver->CreateRenderer(window, flags);
break;
}
}
}
if (!renderer) {
for (index = 0; index < n; ++index) {
if ((driver->info.flags & flags) == flags) {
/* Create a new renderer instance */
renderer = driver->CreateRenderer(window, flags);
if (renderer) {
/* Yay, we got one! */
break;
}
}
}
}
if (index == n) {
SDL_SetError("Couldn't find matching render driver");
return NULL;
}
} else {
SDL_SetError("index must be -1 or in the range of 0 - %d",
return NULL;
}
/* Create a new renderer instance */
renderer = render_drivers[index]->CreateRenderer(window, flags);
}
if (renderer) {
renderer->magic = &renderer_magic;
renderer->window = window;
renderer->scale.x = 1.0f;
renderer->scale.y = 1.0f;
renderer->dpi_scale.x = 1.0f;
renderer->dpi_scale.y = 1.0f;
if (window && renderer->GetOutputSize) {
int output_w, output_h;
if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
SDL_GetWindowSize(renderer->window, &window_w, &window_h);
renderer->dpi_scale.x = (float)window_w / output_w;
renderer->dpi_scale.y = (float)window_h / output_h;
}
}
renderer->hidden = SDL_TRUE;
} else {
renderer->hidden = SDL_FALSE;
}
"Created renderer: %s", renderer->info.name);
}
return renderer;
#else
SDL_SetError("SDL not built with rendering support");
return NULL;
#endif
}
SDL_Renderer* SDL_CreateSoftwareRenderer ( SDL_Surface surface)

Create a 2D software rendering context for a surface.

Parameters
surfaceThe surface where rendering is done.
Returns
A valid rendering context or NULL if there was an error.
See Also
SDL_CreateRenderer()
SDL_DestroyRenderer()

Definition at line 413 of file SDL_render.c.

References SDL_Renderer::magic, NULL, renderer, renderer_magic, SDL_Renderer::scale, SDL_CreateMutex, SDL_RenderSetViewport, SDL_SetError, SW_CreateRendererForSurface(), SDL_Renderer::target_mutex, SDL_FPoint::x, and SDL_FPoint::y.

{
#if !SDL_RENDER_DISABLED
renderer = SW_CreateRendererForSurface(surface);
if (renderer) {
renderer->magic = &renderer_magic;
renderer->scale.x = 1.0f;
renderer->scale.y = 1.0f;
}
return renderer;
#else
SDL_SetError("SDL not built with rendering support");
return NULL;
#endif /* !SDL_RENDER_DISABLED */
}
SDL_Texture* SDL_CreateTexture ( SDL_Renderer renderer,
Uint32  format,
int  access,
int  w,
int  h 
)

Create a texture for a rendering context.

Parameters
rendererThe renderer.
formatThe format of the texture.
accessOne of the enumerated values in SDL_TextureAccess.
wThe width of the texture in pixels.
hThe height of the texture in pixels.
Returns
The created texture is returned, or NULL if no rendering context was active, the format was unsupported, or the width or height were out of range.
Note
The contents of the texture are not defined at creation.
See Also
SDL_QueryTexture()
SDL_UpdateTexture()
SDL_DestroyTexture()

Definition at line 541 of file SDL_render.c.

References SDL_Texture::a, SDL_Texture::access, SDL_Texture::b, CHECK_RENDERER_MAGIC, SDL_Renderer::CreateTexture, SDL_Texture::format, SDL_Texture::g, GetClosestSupportedFormat(), SDL_Texture::h, SDL_Renderer::info, IsSupportedFormat(), SDL_Texture::magic, SDL_RendererInfo::max_texture_height, SDL_RendererInfo::max_texture_width, SDL_Texture::native, SDL_Texture::next, NULL, SDL_Texture::pitch, SDL_Texture::pixels, SDL_Texture::prev, SDL_Texture::r, renderer, SDL_Texture::renderer, SDL_Texture::scaleMode, SDL_BYTESPERPIXEL, SDL_calloc, SDL_CreateTexture, SDL_DestroyTexture, SDL_GetScaleMode(), SDL_ISPIXELFORMAT_FOURCC, SDL_ISPIXELFORMAT_INDEXED, SDL_OutOfMemory, SDL_SetError, SDL_SW_CreateYUVTexture(), SDL_TEXTUREACCESS_STREAMING, SDL_RendererInfo::texture_formats, texture_magic, SDL_Renderer::textures, SDL_Texture::w, and SDL_Texture::yuv.

{
if (!format) {
format = renderer->info.texture_formats[0];
}
SDL_SetError("Invalid texture format");
return NULL;
}
SDL_SetError("Palettized textures are not supported");
return NULL;
}
if (w <= 0 || h <= 0) {
SDL_SetError("Texture dimensions can't be 0");
return NULL;
}
if ((renderer->info.max_texture_width && w > renderer->info.max_texture_width) ||
(renderer->info.max_texture_height && h > renderer->info.max_texture_height)) {
SDL_SetError("Texture dimensions are limited to %dx%d", renderer->info.max_texture_width, renderer->info.max_texture_height);
return NULL;
}
texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
if (!texture) {
return NULL;
}
texture->magic = &texture_magic;
texture->format = format;
texture->access = access;
texture->w = w;
texture->h = h;
texture->r = 255;
texture->g = 255;
texture->b = 255;
texture->a = 255;
texture->renderer = renderer;
texture->next = renderer->textures;
if (renderer->textures) {
renderer->textures->prev = texture;
}
renderer->textures = texture;
if (IsSupportedFormat(renderer, format)) {
if (renderer->CreateTexture(renderer, texture) < 0) {
return NULL;
}
} else {
texture->native = SDL_CreateTexture(renderer,
access, w, h);
if (!texture->native) {
return NULL;
}
/* Swap textures to have texture before texture->native in the list */
texture->native->next = texture->next;
if (texture->native->next) {
texture->native->next->prev = texture->native;
}
texture->prev = texture->native->prev;
if (texture->prev) {
texture->prev->next = texture;
}
texture->native->prev = texture;
texture->next = texture->native;
renderer->textures = texture;
if (!texture->yuv) {
return NULL;
}
/* The pitch is 4 byte aligned */
texture->pitch = (((w * SDL_BYTESPERPIXEL(format)) + 3) & ~3);
texture->pixels = SDL_calloc(1, texture->pitch * h);
if (!texture->pixels) {
return NULL;
}
}
}
return texture;
}
SDL_Texture* SDL_CreateTextureFromSurface ( SDL_Renderer renderer,
SDL_Surface surface 
)

Create a texture from an existing surface.

Parameters
rendererThe renderer.
surfaceThe surface containing pixel data used to fill the texture.
Returns
The created texture is returned, or NULL on error.
Note
The surface is not modified or freed by this function.
See Also
SDL_QueryTexture()
SDL_DestroyTexture()

Definition at line 636 of file SDL_render.c.

References SDL_PixelFormat::Amask, blendMode, CHECK_RENDERER_MAGIC, SDL_Surface::format, SDL_PixelFormat::format, SDL_Surface::h, i, SDL_Renderer::info, NULL, SDL_RendererInfo::num_texture_formats, SDL_Surface::pitch, SDL_Surface::pixels, SDL_AllocFormat, SDL_BLENDMODE_BLEND, SDL_ConvertSurface, SDL_CreateTexture, SDL_DestroyTexture, SDL_FALSE, SDL_FreeFormat, SDL_FreeSurface, SDL_GetSurfaceAlphaMod, SDL_GetSurfaceBlendMode, SDL_GetSurfaceColorMod, SDL_HasColorKey, SDL_ISPIXELFORMAT_ALPHA, SDL_ISPIXELFORMAT_FOURCC, SDL_LockSurface, SDL_MUSTLOCK, SDL_SetError, SDL_SetTextureAlphaMod, SDL_SetTextureBlendMode, SDL_SetTextureColorMod, SDL_TEXTUREACCESS_STATIC, SDL_TRUE, SDL_UnlockSurface, SDL_UpdateTexture, SDL_RendererInfo::texture_formats, and SDL_Surface::w.

{
const SDL_PixelFormat *fmt;
SDL_bool needAlpha;
if (!surface) {
SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
return NULL;
}
/* See what the best texture format is */
fmt = surface->format;
if (fmt->Amask || SDL_HasColorKey(surface)) {
needAlpha = SDL_TRUE;
} else {
needAlpha = SDL_FALSE;
}
format = renderer->info.texture_formats[0];
for (i = 0; i < renderer->info.num_texture_formats; ++i) {
SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
format = renderer->info.texture_formats[i];
break;
}
}
texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
surface->w, surface->h);
if (!texture) {
return NULL;
}
if (format == surface->format->format) {
if (SDL_MUSTLOCK(surface)) {
SDL_LockSurface(surface);
SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
} else {
SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
}
} else {
SDL_PixelFormat *dst_fmt;
SDL_Surface *temp = NULL;
/* Set up a destination surface for the texture update */
dst_fmt = SDL_AllocFormat(format);
if (!dst_fmt) {
return NULL;
}
temp = SDL_ConvertSurface(surface, dst_fmt, 0);
SDL_FreeFormat(dst_fmt);
if (temp) {
SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
} else {
return NULL;
}
}
{
Uint8 r, g, b, a;
SDL_GetSurfaceColorMod(surface, &r, &g, &b);
SDL_SetTextureColorMod(texture, r, g, b);
SDL_GetSurfaceAlphaMod(surface, &a);
if (SDL_HasColorKey(surface)) {
/* We converted to a texture with alpha format */
} else {
SDL_GetSurfaceBlendMode(surface, &blendMode);
SDL_SetTextureBlendMode(texture, blendMode);
}
}
return texture;
}
int SDL_CreateWindowAndRenderer ( int  width,
int  height,
Uint32  window_flags,
SDL_Window **  window,
SDL_Renderer **  renderer 
)

Create a window and default renderer.

Parameters
widthThe width of the window
heightThe height of the window
window_flagsThe flags used to create the window
windowA pointer filled with the window, or NULL on error
rendererA pointer filled with the renderer, or NULL on error
Returns
0 on success, or -1 on error

Definition at line 284 of file SDL_render.c.

References NULL, SDL_CreateRenderer, SDL_CreateWindow, and SDL_WINDOWPOS_UNDEFINED.

{
width, height, window_flags);
if (!*window) {
*renderer = NULL;
return -1;
}
*renderer = SDL_CreateRenderer(*window, -1, 0);
if (!*renderer) {
return -1;
}
return 0;
}
void SDL_DestroyRenderer ( SDL_Renderer renderer)

Destroy the rendering context for a window and free associated textures.

See Also
SDL_CreateRenderer()

Definition at line 2124 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::DestroyRenderer, SDL_Renderer::magic, NULL, SDL_assert, SDL_DelEventWatch, SDL_DestroyMutex, SDL_DestroyTexture, SDL_RendererEventWatch(), SDL_SetWindowData, SDL_WINDOWRENDERDATA, SDL_Renderer::target_mutex, SDL_Renderer::textures, void, and SDL_Renderer::window.

{
CHECK_RENDERER_MAGIC(renderer, );
/* Free existing textures for this renderer */
while (renderer->textures) {
SDL_Texture *tex = renderer->textures; (void) tex;
SDL_assert(tex != renderer->textures); /* satisfy static analysis. */
}
if (renderer->window) {
}
/* It's no longer magical... */
renderer->magic = NULL;
/* Free the target mutex */
renderer->target_mutex = NULL;
/* Free the renderer instance */
renderer->DestroyRenderer(renderer);
}
void SDL_DestroyTexture ( SDL_Texture texture)

Destroy the specified texture.

See Also
SDL_CreateTexture()
SDL_CreateTextureFromSurface()

Definition at line 2089 of file SDL_render.c.

References CHECK_TEXTURE_MAGIC, SDL_Renderer::DestroyTexture, SDL_Texture::magic, SDL_Texture::native, SDL_Texture::next, NULL, SDL_Texture::pixels, SDL_Texture::prev, renderer, SDL_Texture::renderer, SDL_DestroyTexture, SDL_free, SDL_SetRenderTarget, SDL_SW_DestroyYUVTexture(), SDL_Renderer::target, SDL_Renderer::textures, and SDL_Texture::yuv.

{
CHECK_TEXTURE_MAGIC(texture, );
renderer = texture->renderer;
if (texture == renderer->target) {
}
texture->magic = NULL;
if (texture->next) {
texture->next->prev = texture->prev;
}
if (texture->prev) {
texture->prev->next = texture->next;
} else {
renderer->textures = texture->next;
}
if (texture->native) {
}
if (texture->yuv) {
}
SDL_free(texture->pixels);
renderer->DestroyTexture(renderer, texture);
SDL_free(texture);
}
int SDL_GetNumRenderDrivers ( void  )

Get the number of 2D rendering drivers available for the current display.

A render driver is a set of code that handles rendering and texture management on a particular display. Normally there is only one, but some drivers may have several available with different capabilities.

See Also
SDL_GetRenderDriverInfo()
SDL_CreateRenderer()

Definition at line 111 of file SDL_render.c.

References SDL_arraysize.

{
#if !SDL_RENDER_DISABLED
#else
return 0;
#endif
}
int SDL_GetRenderDrawBlendMode ( SDL_Renderer renderer,
SDL_BlendMode blendMode 
)

Get the blend mode used for drawing operations.

Parameters
rendererThe renderer from which blend mode should be queried.
blendModeA pointer filled in with the current blend mode.
Returns
0 on success, or -1 on error
See Also
SDL_SetRenderDrawBlendMode()

Definition at line 1593 of file SDL_render.c.

References SDL_Renderer::blendMode, and CHECK_RENDERER_MAGIC.

{
CHECK_RENDERER_MAGIC(renderer, -1);
*blendMode = renderer->blendMode;
return 0;
}
int SDL_GetRenderDrawColor ( SDL_Renderer renderer,
Uint8 r,
Uint8 g,
Uint8 b,
Uint8 a 
)

Get the color used for drawing operations (Rect, Line and Clear).

Parameters
rendererThe renderer from which drawing color should be queried.
rA pointer to the red value used to draw on the rendering target.
gA pointer to the green value used to draw on the rendering target.
bA pointer to the blue value used to draw on the rendering target.
aA pointer to the alpha value used to draw on the rendering target, usually SDL_ALPHA_OPAQUE (255).
Returns
0 on success, or -1 on error

Definition at line 1560 of file SDL_render.c.

References SDL_Renderer::a, SDL_Renderer::b, CHECK_RENDERER_MAGIC, SDL_Renderer::g, and SDL_Renderer::r.

{
CHECK_RENDERER_MAGIC(renderer, -1);
if (r) {
*r = renderer->r;
}
if (g) {
*g = renderer->g;
}
if (b) {
*b = renderer->b;
}
if (a) {
*a = renderer->a;
}
return 0;
}
int SDL_GetRenderDriverInfo ( int  index,
SDL_RendererInfo info 
)

Get information about a specific 2D rendering driver for the current display.

Parameters
indexThe index of the driver to query information about.
infoA pointer to an SDL_RendererInfo struct to be filled with information on the rendering driver.
Returns
0 on success, -1 if the index was out of range.
See Also
SDL_CreateRenderer()

Definition at line 121 of file SDL_render.c.

References SDL_RenderDriver::info, SDL_GetNumRenderDrivers, and SDL_SetError.

{
#if !SDL_RENDER_DISABLED
return SDL_SetError("index must be in the range of 0 - %d",
}
return 0;
#else
return SDL_SetError("SDL not built with rendering support");
#endif
}
SDL_Renderer* SDL_GetRenderer ( SDL_Window window)

Get the renderer associated with a window.

Definition at line 436 of file SDL_render.c.

References SDL_GetWindowData, and SDL_WINDOWRENDERDATA.

int SDL_GetRendererInfo ( SDL_Renderer renderer,
SDL_RendererInfo info 
)

Get information about a rendering context.

Definition at line 442 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, and SDL_Renderer::info.

{
CHECK_RENDERER_MAGIC(renderer, -1);
*info = renderer->info;
return 0;
}
int SDL_GetRendererOutputSize ( SDL_Renderer renderer,
int *  w,
int *  h 
)

Get the output size in pixels of a rendering context.

Definition at line 451 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::GetOutputSize, NULL, SDL_assert, SDL_GetWindowSize, SDL_QueryTexture, SDL_SetError, SDL_Renderer::target, and SDL_Renderer::window.

{
CHECK_RENDERER_MAGIC(renderer, -1);
if (renderer->target) {
return SDL_QueryTexture(renderer->target, NULL, NULL, w, h);
} else if (renderer->GetOutputSize) {
return renderer->GetOutputSize(renderer, w, h);
} else if (renderer->window) {
SDL_GetWindowSize(renderer->window, w, h);
return 0;
} else {
SDL_assert(0 && "This should never happen");
return SDL_SetError("Renderer doesn't support querying output size");
}
}
SDL_Texture* SDL_GetRenderTarget ( SDL_Renderer renderer)

Get the current render target or NULL for the default render target.

Returns
The current render target
See Also
SDL_SetRenderTarget()

Definition at line 1287 of file SDL_render.c.

References SDL_Renderer::target.

{
return renderer->target;
}
int SDL_GetTextureAlphaMod ( SDL_Texture texture,
Uint8 alpha 
)

Get the additional alpha value used in render copy operations.

Parameters
textureThe texture to query.
alphaA pointer filled in with the current alpha value.
Returns
0 on success, or -1 if the texture is not valid.
See Also
SDL_SetTextureAlphaMod()

Definition at line 811 of file SDL_render.c.

References SDL_Texture::a, and CHECK_TEXTURE_MAGIC.

{
CHECK_TEXTURE_MAGIC(texture, -1);
if (alpha) {
*alpha = texture->a;
}
return 0;
}
int SDL_GetTextureBlendMode ( SDL_Texture texture,
SDL_BlendMode blendMode 
)

Get the blend mode used for texture copy operations.

Parameters
textureThe texture to query.
blendModeA pointer filled in with the current blend mode.
Returns
0 on success, or -1 if the texture is not valid.
See Also
SDL_SetTextureBlendMode()

Definition at line 843 of file SDL_render.c.

References SDL_Texture::blendMode, and CHECK_TEXTURE_MAGIC.

{
CHECK_TEXTURE_MAGIC(texture, -1);
if (blendMode) {
*blendMode = texture->blendMode;
}
return 0;
}
int SDL_GetTextureColorMod ( SDL_Texture texture,
Uint8 r,
Uint8 g,
Uint8 b 
)

Get the additional color value used in render copy operations.

Parameters
textureThe texture to query.
rA pointer filled in with the current red color value.
gA pointer filled in with the current green color value.
bA pointer filled in with the current blue color value.
Returns
0 on success, or -1 if the texture is not valid.
See Also
SDL_SetTextureColorMod()

Definition at line 770 of file SDL_render.c.

References SDL_Texture::b, CHECK_TEXTURE_MAGIC, SDL_Texture::g, and SDL_Texture::r.

{
CHECK_TEXTURE_MAGIC(texture, -1);
if (r) {
*r = texture->r;
}
if (g) {
*g = texture->g;
}
if (b) {
*b = texture->b;
}
return 0;
}
int SDL_GL_BindTexture ( SDL_Texture texture,
float *  texw,
float *  texh 
)

Bind the texture to the current OpenGL/ES/ES2 context for use with OpenGL instructions.

Parameters
textureThe SDL texture to bind
texwA pointer to a float that will be filled with the texture width
texhA pointer to a float that will be filled with the texture height
Returns
0 on success, or -1 if the operation is not supported

Definition at line 2152 of file SDL_render.c.

References CHECK_TEXTURE_MAGIC, SDL_Renderer::GL_BindTexture, SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_GL_BindTexture, and SDL_Unsupported.

{
CHECK_TEXTURE_MAGIC(texture, -1);
renderer = texture->renderer;
if (texture->native) {
return SDL_GL_BindTexture(texture->native, texw, texh);
} else if (renderer && renderer->GL_BindTexture) {
return renderer->GL_BindTexture(renderer, texture, texw, texh);
} else {
return SDL_Unsupported();
}
}
int SDL_GL_UnbindTexture ( SDL_Texture texture)

Unbind a texture from the current OpenGL/ES/ES2 context.

Parameters
textureThe SDL texture to unbind
Returns
0 on success, or -1 if the operation is not supported

Definition at line 2167 of file SDL_render.c.

References CHECK_TEXTURE_MAGIC, SDL_Renderer::GL_UnbindTexture, SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_GL_UnbindTexture, and SDL_Unsupported.

{
CHECK_TEXTURE_MAGIC(texture, -1);
renderer = texture->renderer;
if (texture->native) {
return SDL_GL_UnbindTexture(texture->native);
} else if (renderer && renderer->GL_UnbindTexture) {
return renderer->GL_UnbindTexture(renderer, texture);
}
return SDL_Unsupported();
}
int SDL_LockTexture ( SDL_Texture texture,
const SDL_Rect rect,
void **  pixels,
int *  pitch 
)

Lock a portion of the texture for write-only pixel access.

Parameters
textureThe texture to lock for access, which was created with SDL_TEXTUREACCESS_STREAMING.
rectA pointer to the rectangle to lock for access. If the rect is NULL, the entire texture will be locked.
pixelsThis is filled in with a pointer to the locked pixels, appropriately offset by the locked area.
pitchThis is filled in with the pitch of the locked pixels.
Returns
0 on success, or -1 if the texture is not valid or was not created with SDL_TEXTUREACCESS_STREAMING.
See Also
SDL_UnlockTexture()

Definition at line 1108 of file SDL_render.c.

References SDL_Texture::access, CHECK_TEXTURE_MAGIC, SDL_Texture::h, SDL_Rect::h, SDL_Renderer::LockTexture, SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_LockTextureNative(), SDL_LockTextureYUV(), SDL_SetError, SDL_TEXTUREACCESS_STREAMING, SDL_Texture::w, SDL_Rect::w, SDL_Rect::x, SDL_Rect::y, and SDL_Texture::yuv.

{
SDL_Rect full_rect;
CHECK_TEXTURE_MAGIC(texture, -1);
return SDL_SetError("SDL_LockTexture(): texture must be streaming");
}
if (!rect) {
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = texture->w;
full_rect.h = texture->h;
rect = &full_rect;
}
if (texture->yuv) {
return SDL_LockTextureYUV(texture, rect, pixels, pitch);
} else if (texture->native) {
return SDL_LockTextureNative(texture, rect, pixels, pitch);
} else {
renderer = texture->renderer;
return renderer->LockTexture(renderer, texture, rect, pixels, pitch);
}
}
int SDL_QueryTexture ( SDL_Texture texture,
Uint32 format,
int *  access,
int *  w,
int *  h 
)

Query the attributes of a texture.

Parameters
textureA texture to be queried.
formatA pointer filled in with the raw format of the texture. The actual format may differ, but pixel transfers will use this format.
accessA pointer filled in with the actual access to the texture.
wA pointer filled in with the width of the texture in pixels.
hA pointer filled in with the height of the texture in pixels.
Returns
0 on success, or -1 if the texture is not valid.

Definition at line 724 of file SDL_render.c.

References SDL_Texture::access, CHECK_TEXTURE_MAGIC, SDL_Texture::format, SDL_Texture::h, and SDL_Texture::w.

{
CHECK_TEXTURE_MAGIC(texture, -1);
if (format) {
*format = texture->format;
}
if (access) {
*access = texture->access;
}
if (w) {
*w = texture->w;
}
if (h) {
*h = texture->h;
}
return 0;
}
int SDL_RenderClear ( SDL_Renderer renderer)

Clear the current rendering target with the drawing color.

This function clears the entire rendering target, ignoring the viewport and the clip rectangle.

Returns
0 on success, or -1 on error

Definition at line 1602 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::hidden, and SDL_Renderer::RenderClear.

{
CHECK_RENDERER_MAGIC(renderer, -1);
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
return renderer->RenderClear(renderer);
}
int SDL_RenderCopy ( SDL_Renderer renderer,
SDL_Texture texture,
const SDL_Rect srcrect,
const SDL_Rect dstrect 
)

Copy a portion of the texture to the current rendering target.

Parameters
rendererThe renderer which should copy parts of a texture.
textureThe source texture.
srcrectA pointer to the source rectangle, or NULL for the entire texture.
dstrectA pointer to the destination rectangle, or NULL for the entire rendering target.
Returns
0 on success, or -1 on error

Definition at line 1916 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, CHECK_TEXTURE_MAGIC, SDL_FRect::h, SDL_Texture::h, SDL_Rect::h, SDL_Renderer::hidden, SDL_Texture::native, SDL_Renderer::RenderCopy, SDL_Texture::renderer, SDL_Renderer::scale, SDL_HasIntersection, SDL_IntersectRect, SDL_RenderGetViewport, SDL_SetError, SDL_FRect::w, SDL_Texture::w, SDL_Rect::w, SDL_FPoint::x, SDL_FRect::x, SDL_Rect::x, SDL_FPoint::y, SDL_FRect::y, and SDL_Rect::y.

{
SDL_Rect real_srcrect = { 0, 0, 0, 0 };
SDL_Rect real_dstrect = { 0, 0, 0, 0 };
SDL_FRect frect;
CHECK_RENDERER_MAGIC(renderer, -1);
CHECK_TEXTURE_MAGIC(texture, -1);
if (renderer != texture->renderer) {
return SDL_SetError("Texture was not created with this renderer");
}
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
real_srcrect.x = 0;
real_srcrect.y = 0;
real_srcrect.w = texture->w;
real_srcrect.h = texture->h;
if (srcrect) {
if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
return 0;
}
}
SDL_RenderGetViewport(renderer, &real_dstrect);
real_dstrect.x = 0;
real_dstrect.y = 0;
if (dstrect) {
if (!SDL_HasIntersection(dstrect, &real_dstrect)) {
return 0;
}
real_dstrect = *dstrect;
}
if (texture->native) {
texture = texture->native;
}
frect.x = real_dstrect.x * renderer->scale.x;
frect.y = real_dstrect.y * renderer->scale.y;
frect.w = real_dstrect.w * renderer->scale.x;
frect.h = real_dstrect.h * renderer->scale.y;
return renderer->RenderCopy(renderer, texture, &real_srcrect, &frect);
}
int SDL_RenderCopyEx ( SDL_Renderer renderer,
SDL_Texture texture,
const SDL_Rect srcrect,
const SDL_Rect dstrect,
const double  angle,
const SDL_Point center,
const SDL_RendererFlip  flip 
)

Copy a portion of the source texture to the current rendering target, rotating it by angle around the given center.

Parameters
rendererThe renderer which should copy parts of a texture.
textureThe source texture.
srcrectA pointer to the source rectangle, or NULL for the entire texture.
dstrectA pointer to the destination rectangle, or NULL for the entire rendering target.
angleAn angle in degrees that indicates the rotation that will be applied to dstrect, rotating it in a clockwise direction
centerA pointer to a point indicating the point around which dstrect will be rotated (if NULL, rotation will be done around dstrect.w/2, dstrect.h/2).
flipAn SDL_RendererFlip value stating which flipping actions should be performed on the texture
Returns
0 on success, or -1 on error

Definition at line 1969 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, CHECK_TEXTURE_MAGIC, SDL_FRect::h, SDL_Texture::h, SDL_Rect::h, SDL_Renderer::hidden, SDL_Texture::native, SDL_Renderer::RenderCopyEx, SDL_Texture::renderer, SDL_Renderer::scale, SDL_FLIP_NONE, SDL_IntersectRect, SDL_RenderCopy, SDL_RenderGetViewport, SDL_SetError, SDL_FRect::w, SDL_Texture::w, SDL_Rect::w, SDL_FPoint::x, SDL_Point::x, SDL_FRect::x, SDL_Rect::x, SDL_FPoint::y, SDL_Point::y, SDL_FRect::y, and SDL_Rect::y.

{
SDL_Rect real_srcrect = { 0, 0, 0, 0 };
SDL_Rect real_dstrect = { 0, 0, 0, 0 };
SDL_Point real_center;
SDL_FRect frect;
SDL_FPoint fcenter;
if (flip == SDL_FLIP_NONE && (int)(angle/360) == angle/360) { /* fast path when we don't need rotation or flipping */
return SDL_RenderCopy(renderer, texture, srcrect, dstrect);
}
CHECK_RENDERER_MAGIC(renderer, -1);
CHECK_TEXTURE_MAGIC(texture, -1);
if (renderer != texture->renderer) {
return SDL_SetError("Texture was not created with this renderer");
}
if (!renderer->RenderCopyEx) {
return SDL_SetError("Renderer does not support RenderCopyEx");
}
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
real_srcrect.x = 0;
real_srcrect.y = 0;
real_srcrect.w = texture->w;
real_srcrect.h = texture->h;
if (srcrect) {
if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
return 0;
}
}
/* We don't intersect the dstrect with the viewport as RenderCopy does because of potential rotation clipping issues... TODO: should we? */
if (dstrect) {
real_dstrect = *dstrect;
} else {
SDL_RenderGetViewport(renderer, &real_dstrect);
real_dstrect.x = 0;
real_dstrect.y = 0;
}
if (texture->native) {
texture = texture->native;
}
if (center) {
real_center = *center;
} else {
real_center.x = real_dstrect.w/2;
real_center.y = real_dstrect.h/2;
}
frect.x = real_dstrect.x * renderer->scale.x;
frect.y = real_dstrect.y * renderer->scale.y;
frect.w = real_dstrect.w * renderer->scale.x;
frect.h = real_dstrect.h * renderer->scale.y;
fcenter.x = real_center.x * renderer->scale.x;
fcenter.y = real_center.y * renderer->scale.y;
return renderer->RenderCopyEx(renderer, texture, &real_srcrect, &frect, angle, &fcenter, flip);
}
int SDL_RenderDrawLine ( SDL_Renderer renderer,
int  x1,
int  y1,
int  x2,
int  y2 
)

Draw a line on the current rendering target.

Parameters
rendererThe renderer which should draw a line.
x1The x coordinate of the start point.
y1The y coordinate of the start point.
x2The x coordinate of the end point.
y2The y coordinate of the end point.
Returns
0 on success, or -1 on error

Definition at line 1692 of file SDL_render.c.

References SDL_RenderDrawLines, SDL_Point::x, and SDL_Point::y.

{
points[0].x = x1;
points[0].y = y1;
points[1].x = x2;
points[1].y = y2;
return SDL_RenderDrawLines(renderer, points, 2);
}
int SDL_RenderDrawLines ( SDL_Renderer renderer,
const SDL_Point points,
int  count 
)

Draw a series of connected lines on the current rendering target.

Parameters
rendererThe renderer which should draw multiple lines.
pointsThe points along the lines
countThe number of points, drawing count-1 lines
Returns
0 on success, or -1 on error

Definition at line 1760 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::hidden, i, SDL_Renderer::RenderDrawLines, RenderDrawLinesWithRects(), SDL_Renderer::scale, SDL_OutOfMemory, SDL_SetError, SDL_stack_alloc, SDL_stack_free, SDL_FPoint::x, SDL_Point::x, SDL_FPoint::y, and SDL_Point::y.

{
SDL_FPoint *fpoints;
int i;
int status;
CHECK_RENDERER_MAGIC(renderer, -1);
if (!points) {
return SDL_SetError("SDL_RenderDrawLines(): Passed NULL points");
}
if (count < 2) {
return 0;
}
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
return RenderDrawLinesWithRects(renderer, points, count);
}
if (!fpoints) {
return SDL_OutOfMemory();
}
for (i = 0; i < count; ++i) {
fpoints[i].x = points[i].x * renderer->scale.x;
fpoints[i].y = points[i].y * renderer->scale.y;
}
status = renderer->RenderDrawLines(renderer, fpoints, count);
SDL_stack_free(fpoints);
return status;
}
int SDL_RenderDrawPoint ( SDL_Renderer renderer,
int  x,
int  y 
)

Draw a point on the current rendering target.

Parameters
rendererThe renderer which should draw a point.
xThe x coordinate of the point.
yThe y coordinate of the point.
Returns
0 on success, or -1 on error

Definition at line 1614 of file SDL_render.c.

References SDL_RenderDrawPoints, SDL_Point::x, and SDL_Point::y.

{
SDL_Point point;
point.x = x;
point.y = y;
return SDL_RenderDrawPoints(renderer, &point, 1);
}
int SDL_RenderDrawPoints ( SDL_Renderer renderer,
const SDL_Point points,
int  count 
)

Draw multiple points on the current rendering target.

Parameters
rendererThe renderer which should draw multiple points.
pointsThe points to draw
countThe number of points to draw
Returns
0 on success, or -1 on error

Definition at line 1650 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::hidden, i, SDL_Renderer::RenderDrawPoints, RenderDrawPointsWithRects(), SDL_Renderer::scale, SDL_OutOfMemory, SDL_SetError, SDL_stack_alloc, SDL_stack_free, SDL_FPoint::x, SDL_Point::x, SDL_FPoint::y, and SDL_Point::y.

{
SDL_FPoint *fpoints;
int i;
int status;
CHECK_RENDERER_MAGIC(renderer, -1);
if (!points) {
return SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points");
}
if (count < 1) {
return 0;
}
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
return RenderDrawPointsWithRects(renderer, points, count);
}
if (!fpoints) {
return SDL_OutOfMemory();
}
for (i = 0; i < count; ++i) {
fpoints[i].x = points[i].x * renderer->scale.x;
fpoints[i].y = points[i].y * renderer->scale.y;
}
status = renderer->RenderDrawPoints(renderer, fpoints, count);
SDL_stack_free(fpoints);
return status;
}
int SDL_RenderDrawRect ( SDL_Renderer renderer,
const SDL_Rect rect 
)

Draw a rectangle on the current rendering target.

Parameters
rendererThe renderer which should draw a rectangle.
rectA pointer to the destination rectangle, or NULL to outline the entire rendering target.
Returns
0 on success, or -1 on error

Definition at line 1802 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Rect::h, SDL_RenderDrawLines, SDL_RenderGetViewport, SDL_Rect::w, SDL_Point::x, SDL_Rect::x, SDL_Point::y, and SDL_Rect::y.

{
SDL_Rect full_rect;
CHECK_RENDERER_MAGIC(renderer, -1);
/* If 'rect' == NULL, then outline the whole surface */
if (!rect) {
SDL_RenderGetViewport(renderer, &full_rect);
full_rect.x = 0;
full_rect.y = 0;
rect = &full_rect;
}
points[0].x = rect->x;
points[0].y = rect->y;
points[1].x = rect->x+rect->w-1;
points[1].y = rect->y;
points[2].x = rect->x+rect->w-1;
points[2].y = rect->y+rect->h-1;
points[3].x = rect->x;
points[3].y = rect->y+rect->h-1;
points[4].x = rect->x;
points[4].y = rect->y;
return SDL_RenderDrawLines(renderer, points, 5);
}
int SDL_RenderDrawRects ( SDL_Renderer renderer,
const SDL_Rect rects,
int  count 
)

Draw some number of rectangles on the current rendering target.

Parameters
rendererThe renderer which should draw multiple rectangles.
rectsA pointer to an array of destination rectangles.
countThe number of rectangles.
Returns
0 on success, or -1 on error

Definition at line 1831 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::hidden, i, SDL_RenderDrawRect, and SDL_SetError.

{
int i;
CHECK_RENDERER_MAGIC(renderer, -1);
if (!rects) {
return SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects");
}
if (count < 1) {
return 0;
}
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
for (i = 0; i < count; ++i) {
if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) {
return -1;
}
}
return 0;
}
int SDL_RenderFillRect ( SDL_Renderer renderer,
const SDL_Rect rect 
)

Fill a rectangle on the current rendering target with the drawing color.

Parameters
rendererThe renderer which should fill a rectangle.
rectA pointer to the destination rectangle, or NULL for the entire rendering target.
Returns
0 on success, or -1 on error

Definition at line 1859 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_RenderFillRects, SDL_RenderGetViewport, SDL_Rect::x, and SDL_Rect::y.

{
SDL_Rect full_rect = { 0, 0, 0, 0 };
CHECK_RENDERER_MAGIC(renderer, -1);
/* If 'rect' == NULL, then outline the whole surface */
if (!rect) {
SDL_RenderGetViewport(renderer, &full_rect);
full_rect.x = 0;
full_rect.y = 0;
rect = &full_rect;
}
return SDL_RenderFillRects(renderer, rect, 1);
}
int SDL_RenderFillRects ( SDL_Renderer renderer,
const SDL_Rect rects,
int  count 
)

Fill some number of rectangles on the current rendering target with the drawing color.

Parameters
rendererThe renderer which should fill multiple rectangles.
rectsA pointer to an array of destination rectangles.
countThe number of rectangles.
Returns
0 on success, or -1 on error

Definition at line 1876 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_FRect::h, SDL_Rect::h, SDL_Renderer::hidden, i, SDL_Renderer::RenderFillRects, SDL_Renderer::scale, SDL_OutOfMemory, SDL_SetError, SDL_stack_alloc, SDL_stack_free, SDL_FRect::w, SDL_Rect::w, SDL_FPoint::x, SDL_FRect::x, SDL_Rect::x, SDL_FPoint::y, SDL_FRect::y, and SDL_Rect::y.

{
SDL_FRect *frects;
int i;
int status;
CHECK_RENDERER_MAGIC(renderer, -1);
if (!rects) {
return SDL_SetError("SDL_RenderFillRects(): Passed NULL rects");
}
if (count < 1) {
return 0;
}
/* Don't draw while we're hidden */
if (renderer->hidden) {
return 0;
}
if (!frects) {
return SDL_OutOfMemory();
}
for (i = 0; i < count; ++i) {
frects[i].x = rects[i].x * renderer->scale.x;
frects[i].y = rects[i].y * renderer->scale.y;
frects[i].w = rects[i].w * renderer->scale.x;
frects[i].h = rects[i].h * renderer->scale.y;
}
status = renderer->RenderFillRects(renderer, frects, count);
SDL_stack_free(frects);
return status;
}
void SDL_RenderGetClipRect ( SDL_Renderer renderer,
SDL_Rect rect 
)

Get the clip rectangle for the current target.

Parameters
rendererThe renderer from which clip rectangle should be queried.
rectA pointer filled in with the current clip rectangle, or an empty rectangle if clipping is disabled.
See Also
SDL_RenderSetClipRect()

Definition at line 1504 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::clip_rect, SDL_Rect::h, SDL_Renderer::scale, SDL_Rect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FPoint::y, and SDL_Rect::y.

{
if (rect) {
rect->x = (int)(renderer->clip_rect.x / renderer->scale.x);
rect->y = (int)(renderer->clip_rect.y / renderer->scale.y);
rect->w = (int)(renderer->clip_rect.w / renderer->scale.x);
rect->h = (int)(renderer->clip_rect.h / renderer->scale.y);
}
}
SDL_bool SDL_RenderGetIntegerScale ( SDL_Renderer renderer)

Get whether integer scales are forced for resolution-independent rendering.

Parameters
rendererThe renderer from which integer scaling should be queried.
See Also
SDL_RenderSetIntegerScale()

Definition at line 1445 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::integer_scale, and SDL_FALSE.

{
return renderer->integer_scale;
}
void SDL_RenderGetLogicalSize ( SDL_Renderer renderer,
int *  w,
int *  h 
)

Get device independent resolution for rendering.

Parameters
rendererThe renderer from which resolution should be queried.
wA pointer filled with the width of the logical resolution
hA pointer filled with the height of the logical resolution
See Also
SDL_RenderSetLogicalSize()

Definition at line 1422 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::logical_h, and SDL_Renderer::logical_w.

{
CHECK_RENDERER_MAGIC(renderer, );
if (w) {
*w = renderer->logical_w;
}
if (h) {
*h = renderer->logical_h;
}
}
void* SDL_RenderGetMetalCommandEncoder ( SDL_Renderer renderer)

Get the Metal command encoder for the current frame.

Parameters
rendererThe renderer to query
Returns
id<MTLRenderCommandEncoder> on success, or NULL if the renderer isn't a Metal renderer
See Also
SDL_RenderGetMetalLayer()

Definition at line 2194 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::GetMetalCommandEncoder, and NULL.

{
if (renderer->GetMetalCommandEncoder) {
return renderer->GetMetalCommandEncoder(renderer);
}
return NULL;
}
void* SDL_RenderGetMetalLayer ( SDL_Renderer renderer)

Get the CAMetalLayer associated with the given Metal renderer.

Parameters
rendererThe renderer to query
Returns
CAMetalLayer* on success, or NULL if the renderer isn't a Metal renderer
See Also
SDL_RenderGetMetalCommandEncoder()

Definition at line 2183 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::GetMetalLayer, and NULL.

{
if (renderer->GetMetalLayer) {
return renderer->GetMetalLayer(renderer);
}
return NULL;
}
void SDL_RenderGetScale ( SDL_Renderer renderer,
float *  scaleX,
float *  scaleY 
)

Get the drawing scale for the current target.

Parameters
rendererThe renderer from which drawing scale should be queried.
scaleXA pointer filled in with the horizontal scaling factor
scaleYA pointer filled in with the vertical scaling factor
See Also
SDL_RenderSetScale()

Definition at line 1534 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::scale, SDL_FPoint::x, and SDL_FPoint::y.

{
CHECK_RENDERER_MAGIC(renderer, );
if (scaleX) {
*scaleX = renderer->scale.x;
}
if (scaleY) {
*scaleY = renderer->scale.y;
}
}
void SDL_RenderGetViewport ( SDL_Renderer renderer,
SDL_Rect rect 
)

Get the drawing area for the current target.

See Also
SDL_RenderSetViewport()

Definition at line 1473 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Rect::h, SDL_Renderer::scale, SDL_Renderer::viewport, SDL_Rect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FPoint::y, and SDL_Rect::y.

{
CHECK_RENDERER_MAGIC(renderer, );
if (rect) {
rect->x = (int)(renderer->viewport.x / renderer->scale.x);
rect->y = (int)(renderer->viewport.y / renderer->scale.y);
rect->w = (int)(renderer->viewport.w / renderer->scale.x);
rect->h = (int)(renderer->viewport.h / renderer->scale.y);
}
}
SDL_bool SDL_RenderIsClipEnabled ( SDL_Renderer renderer)

Get whether clipping is enabled on the given renderer.

Parameters
rendererThe renderer from which clip state should be queried.
See Also
SDL_RenderGetClipRect()

Definition at line 1517 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::clipping_enabled, and SDL_FALSE.

{
return renderer->clipping_enabled;
}
void SDL_RenderPresent ( SDL_Renderer renderer)

Update the screen with rendering performed.

Definition at line 2077 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::hidden, and SDL_Renderer::RenderPresent.

{
CHECK_RENDERER_MAGIC(renderer, );
/* Don't draw while we're hidden */
if (renderer->hidden) {
return;
}
renderer->RenderPresent(renderer);
}
int SDL_RenderReadPixels ( SDL_Renderer renderer,
const SDL_Rect rect,
Uint32  format,
void pixels,
int  pitch 
)

Read pixels from the current rendering target.

Parameters
rendererThe renderer from which pixels should be read.
rectA pointer to the rectangle to read, or NULL for the entire render target.
formatThe desired format of the pixel data, or 0 to use the format of the rendering target
pixelsA pointer to be filled in with the pixel data
pitchThe pitch of the pixels parameter.
Returns
0 on success, or -1 if pixel reading is not supported.
Warning
This is a very slow operation, and should not be used frequently.

Definition at line 2040 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Rect::h, SDL_Renderer::RenderReadPixels, SDL_BYTESPERPIXEL, SDL_GetWindowPixelFormat, SDL_IntersectRect, SDL_Unsupported, SDL_Renderer::viewport, SDL_Rect::w, SDL_Renderer::window, SDL_Rect::x, and SDL_Rect::y.

{
SDL_Rect real_rect;
CHECK_RENDERER_MAGIC(renderer, -1);
if (!renderer->RenderReadPixels) {
return SDL_Unsupported();
}
if (!format) {
}
real_rect.x = renderer->viewport.x;
real_rect.y = renderer->viewport.y;
real_rect.w = renderer->viewport.w;
real_rect.h = renderer->viewport.h;
if (rect) {
if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
return 0;
}
if (real_rect.y > rect->y) {
pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
}
if (real_rect.x > rect->x) {
pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
}
}
return renderer->RenderReadPixels(renderer, &real_rect,
format, pixels, pitch);
}
int SDL_RenderSetClipRect ( SDL_Renderer renderer,
const SDL_Rect rect 
)

Set the clip rectangle for the current target.

Parameters
rendererThe renderer for which clip rectangle should be set.
rectA pointer to the rectangle to set as the clip rectangle, or NULL to disable clipping.
Returns
0 on success, or -1 on error
See Also
SDL_RenderGetClipRect()

Definition at line 1486 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::clip_rect, SDL_Renderer::clipping_enabled, SDL_Rect::h, SDL_Renderer::scale, SDL_ceil, SDL_FALSE, SDL_floor, SDL_TRUE, SDL_zero, SDL_Renderer::UpdateClipRect, SDL_Rect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FPoint::y, and SDL_Rect::y.

{
CHECK_RENDERER_MAGIC(renderer, -1)
if (rect) {
renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x);
renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y);
renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x);
renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y);
} else {
SDL_zero(renderer->clip_rect);
}
return renderer->UpdateClipRect(renderer);
}
int SDL_RenderSetIntegerScale ( SDL_Renderer renderer,
SDL_bool  enable 
)

Set whether to force integer scales for resolution-independent rendering.

Parameters
rendererThe renderer for which integer scaling should be set.
enableEnable or disable integer scaling

This function restricts the logical viewport to integer values - that is, when a resolution is between two multiples of a logical size, the viewport size is rounded down to the lower multiple.

See Also
SDL_RenderSetLogicalSize()

Definition at line 1435 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::integer_scale, and UpdateLogicalSize().

{
CHECK_RENDERER_MAGIC(renderer, -1);
renderer->integer_scale = enable;
return UpdateLogicalSize(renderer);
}
int SDL_RenderSetLogicalSize ( SDL_Renderer renderer,
int  w,
int  h 
)

Set device independent resolution for rendering.

Parameters
rendererThe renderer for which resolution should be set.
wThe width of the logical resolution
hThe height of the logical resolution

This function uses the viewport and scaling functionality to allow a fixed logical resolution for rendering, regardless of the actual output resolution. If the actual output resolution doesn't have the same aspect ratio the output rendering will be centered within the output display.

If the output display is a window, mouse events in the window will be filtered and scaled so they seem to arrive within the logical resolution.

Note
If this function results in scaling or subpixel drawing by the rendering backend, it will be handled using the appropriate quality hints.
See Also
SDL_RenderGetLogicalSize()
SDL_RenderSetScale()
SDL_RenderSetViewport()

Definition at line 1402 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::logical_h, SDL_Renderer::logical_w, NULL, SDL_RenderSetScale, SDL_RenderSetViewport, and UpdateLogicalSize().

{
CHECK_RENDERER_MAGIC(renderer, -1);
if (!w || !h) {
/* Clear any previous logical resolution */
renderer->logical_w = 0;
renderer->logical_h = 0;
SDL_RenderSetScale(renderer, 1.0f, 1.0f);
return 0;
}
renderer->logical_w = w;
renderer->logical_h = h;
return UpdateLogicalSize(renderer);
}
int SDL_RenderSetScale ( SDL_Renderer renderer,
float  scaleX,
float  scaleY 
)

Set the drawing scale for rendering on the current target.

Parameters
rendererThe renderer for which the drawing scale should be set.
scaleXThe horizontal scaling factor
scaleYThe vertical scaling factor

The drawing coordinates are scaled by the x/y scaling factors before they are used by the renderer. This allows resolution independent drawing with a single coordinate system.

Note
If this results in scaling or subpixel drawing by the rendering backend, it will be handled using the appropriate quality hints. For best results use integer scaling factors.
See Also
SDL_RenderGetScale()
SDL_RenderSetLogicalSize()

Definition at line 1524 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Renderer::scale, SDL_FPoint::x, and SDL_FPoint::y.

{
CHECK_RENDERER_MAGIC(renderer, -1);
renderer->scale.x = scaleX;
renderer->scale.y = scaleY;
return 0;
}
int SDL_RenderSetViewport ( SDL_Renderer renderer,
const SDL_Rect rect 
)

Set the drawing area for rendering on the current target.

Parameters
rendererThe renderer for which the drawing area should be set.
rectThe rectangle representing the drawing area, or NULL to set the viewport to the entire target.

The x,y of the viewport rect represents the origin for rendering.

Returns
0 on success, or -1 on error
Note
If the window associated with the renderer is resized, the viewport is automatically reset.
See Also
SDL_RenderGetViewport()
SDL_RenderSetLogicalSize()

Definition at line 1453 of file SDL_render.c.

References CHECK_RENDERER_MAGIC, SDL_Rect::h, SDL_Renderer::scale, SDL_ceil, SDL_floor, SDL_GetRendererOutputSize, SDL_Renderer::UpdateViewport, SDL_Renderer::viewport, SDL_Rect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FPoint::y, and SDL_Rect::y.

{
CHECK_RENDERER_MAGIC(renderer, -1);
if (rect) {
renderer->viewport.x = (int)SDL_floor(rect->x * renderer->scale.x);
renderer->viewport.y = (int)SDL_floor(rect->y * renderer->scale.y);
renderer->viewport.w = (int)SDL_ceil(rect->w * renderer->scale.x);
renderer->viewport.h = (int)SDL_ceil(rect->h * renderer->scale.y);
} else {
renderer->viewport.x = 0;
renderer->viewport.y = 0;
if (SDL_GetRendererOutputSize(renderer, &renderer->viewport.w, &renderer->viewport.h) < 0) {
return -1;
}
}
return renderer->UpdateViewport(renderer);
}
SDL_bool SDL_RenderTargetSupported ( SDL_Renderer renderer)

Determines whether a window supports the use of render targets.

Parameters
rendererThe renderer that will be checked
Returns
SDL_TRUE if supported, SDL_FALSE if not.

Definition at line 1201 of file SDL_render.c.

References SDL_RendererInfo::flags, SDL_Renderer::info, SDL_FALSE, SDL_RENDERER_TARGETTEXTURE, and SDL_Renderer::SetRenderTarget.

{
if (!renderer || !renderer->SetRenderTarget) {
return SDL_FALSE;
}
return (renderer->info.flags & SDL_RENDERER_TARGETTEXTURE) != 0;
}
int SDL_SetRenderDrawBlendMode ( SDL_Renderer renderer,
SDL_BlendMode  blendMode 
)

Set the blend mode used for drawing operations (Fill and Line).

Parameters
rendererThe renderer for which blend mode should be set.
blendModeSDL_BlendMode to use for blending.
Returns
0 on success, or -1 on error
Note
If the blend mode is not supported, the closest supported mode is chosen.
See Also
SDL_GetRenderDrawBlendMode()

Definition at line 1581 of file SDL_render.c.

References blendMode, SDL_Renderer::blendMode, CHECK_RENDERER_MAGIC, IsSupportedBlendMode(), and SDL_Unsupported.

{
CHECK_RENDERER_MAGIC(renderer, -1);
if (!IsSupportedBlendMode(renderer, blendMode)) {
return SDL_Unsupported();
}
renderer->blendMode = blendMode;
return 0;
}
int SDL_SetRenderDrawColor ( SDL_Renderer renderer,
Uint8  r,
Uint8  g,
Uint8  b,
Uint8  a 
)

Set the color used for drawing operations (Rect, Line and Clear).

Parameters
rendererThe renderer for which drawing color should be set.
rThe red value used to draw on the rendering target.
gThe green value used to draw on the rendering target.
bThe blue value used to draw on the rendering target.
aThe alpha value used to draw on the rendering target, usually SDL_ALPHA_OPAQUE (255).
Returns
0 on success, or -1 on error

Definition at line 1547 of file SDL_render.c.

References SDL_Renderer::a, SDL_Renderer::b, CHECK_RENDERER_MAGIC, SDL_Renderer::g, and SDL_Renderer::r.

{
CHECK_RENDERER_MAGIC(renderer, -1);
renderer->r = r;
renderer->g = g;
renderer->b = b;
renderer->a = a;
return 0;
}
int SDL_SetRenderTarget ( SDL_Renderer renderer,
SDL_Texture texture 
)

Set a texture as the current rendering target.

Parameters
rendererThe renderer.
textureThe targeted texture, which must be created with the SDL_TEXTUREACCESS_TARGET flag, or NULL for the default render target
Returns
0 on success, or -1 on error
See Also
SDL_GetRenderTarget()

Definition at line 1210 of file SDL_render.c.

References SDL_Texture::access, CHECK_TEXTURE_MAGIC, SDL_Renderer::clip_rect, SDL_Renderer::clip_rect_backup, SDL_Renderer::clipping_enabled, SDL_Renderer::clipping_enabled_backup, SDL_Texture::h, SDL_Rect::h, SDL_Renderer::logical_h, SDL_Renderer::logical_h_backup, SDL_Renderer::logical_w, SDL_Renderer::logical_w_backup, SDL_Texture::native, SDL_Texture::renderer, SDL_Renderer::scale, SDL_Renderer::scale_backup, SDL_FALSE, SDL_LockMutex, SDL_RenderTargetSupported, SDL_SetError, SDL_TEXTUREACCESS_TARGET, SDL_UnlockMutex, SDL_Unsupported, SDL_zero, SDL_Renderer::SetRenderTarget, SDL_Renderer::target, SDL_Renderer::target_mutex, SDL_Renderer::UpdateClipRect, SDL_Renderer::UpdateViewport, SDL_Renderer::viewport, SDL_Renderer::viewport_backup, SDL_Texture::w, SDL_Rect::w, SDL_FPoint::x, SDL_Rect::x, SDL_FPoint::y, and SDL_Rect::y.

{
if (!SDL_RenderTargetSupported(renderer)) {
return SDL_Unsupported();
}
if (texture == renderer->target) {
/* Nothing to do! */
return 0;
}
/* texture == NULL is valid and means reset the target to the window */
if (texture) {
CHECK_TEXTURE_MAGIC(texture, -1);
if (renderer != texture->renderer) {
return SDL_SetError("Texture was not created with this renderer");
}
if (texture->access != SDL_TEXTUREACCESS_TARGET) {
return SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET");
}
if (texture->native) {
/* Always render to the native texture */
texture = texture->native;
}
}
if (texture && !renderer->target) {
/* Make a backup of the viewport */
renderer->viewport_backup = renderer->viewport;
renderer->clip_rect_backup = renderer->clip_rect;
renderer->scale_backup = renderer->scale;
renderer->logical_w_backup = renderer->logical_w;
renderer->logical_h_backup = renderer->logical_h;
}
renderer->target = texture;
if (renderer->SetRenderTarget(renderer, texture) < 0) {
return -1;
}
if (texture) {
renderer->viewport.x = 0;
renderer->viewport.y = 0;
renderer->viewport.w = texture->w;
renderer->viewport.h = texture->h;
SDL_zero(renderer->clip_rect);
renderer->scale.x = 1.0f;
renderer->scale.y = 1.0f;
renderer->logical_w = texture->w;
renderer->logical_h = texture->h;
} else {
renderer->viewport = renderer->viewport_backup;
renderer->clip_rect = renderer->clip_rect_backup;
renderer->scale = renderer->scale_backup;
renderer->logical_w = renderer->logical_w_backup;
renderer->logical_h = renderer->logical_h_backup;
}
if (renderer->UpdateViewport(renderer) < 0) {
return -1;
}
if (renderer->UpdateClipRect(renderer) < 0) {
return -1;
}
/* All set! */
return 0;
}
int SDL_SetTextureAlphaMod ( SDL_Texture texture,
Uint8  alpha 
)

Set an additional alpha value used in render copy operations.

Parameters
textureThe texture to update.
alphaThe alpha value multiplied into copy operations.
Returns
0 on success, or -1 if the texture is not valid or alpha modulation is not supported.
See Also
SDL_GetTextureAlphaMod()

Definition at line 788 of file SDL_render.c.

References SDL_Texture::a, CHECK_TEXTURE_MAGIC, SDL_Texture::modMode, SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_SetTextureAlphaMod, SDL_TEXTUREMODULATE_ALPHA, and SDL_Renderer::SetTextureAlphaMod.

{
CHECK_TEXTURE_MAGIC(texture, -1);
renderer = texture->renderer;
if (alpha < 255) {
} else {
}
texture->a = alpha;
if (texture->native) {
return SDL_SetTextureAlphaMod(texture->native, alpha);
} else if (renderer->SetTextureAlphaMod) {
return renderer->SetTextureAlphaMod(renderer, texture);
} else {
return 0;
}
}
int SDL_SetTextureBlendMode ( SDL_Texture texture,
SDL_BlendMode  blendMode 
)

Set the blend mode used for texture copy operations.

Parameters
textureThe texture to update.
blendModeSDL_BlendMode to use for texture blending.
Returns
0 on success, or -1 if the texture is not valid or the blend mode is not supported.
Note
If the blend mode is not supported, the closest supported mode is chosen.
See Also
SDL_GetTextureBlendMode()

Definition at line 822 of file SDL_render.c.

References blendMode, SDL_Texture::blendMode, CHECK_TEXTURE_MAGIC, IsSupportedBlendMode(), SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_SetTextureBlendMode, SDL_Unsupported, and SDL_Renderer::SetTextureBlendMode.

{
CHECK_TEXTURE_MAGIC(texture, -1);
renderer = texture->renderer;
if (!IsSupportedBlendMode(renderer, blendMode)) {
return SDL_Unsupported();
}
texture->blendMode = blendMode;
if (texture->native) {
} else if (renderer->SetTextureBlendMode) {
return renderer->SetTextureBlendMode(renderer, texture);
} else {
return 0;
}
}
int SDL_SetTextureColorMod ( SDL_Texture texture,
Uint8  r,
Uint8  g,
Uint8  b 
)

Set an additional color value used in render copy operations.

Parameters
textureThe texture to update.
rThe red color value multiplied into copy operations.
gThe green color value multiplied into copy operations.
bThe blue color value multiplied into copy operations.
Returns
0 on success, or -1 if the texture is not valid or color modulation is not supported.
See Also
SDL_GetTextureColorMod()

Definition at line 745 of file SDL_render.c.

References SDL_Texture::b, CHECK_TEXTURE_MAGIC, SDL_Texture::g, SDL_Texture::modMode, SDL_Texture::native, SDL_Texture::r, renderer, SDL_Texture::renderer, SDL_SetTextureColorMod, SDL_TEXTUREMODULATE_COLOR, and SDL_Renderer::SetTextureColorMod.

{
CHECK_TEXTURE_MAGIC(texture, -1);
renderer = texture->renderer;
if (r < 255 || g < 255 || b < 255) {
} else {
}
texture->r = r;
texture->g = g;
texture->b = b;
if (texture->native) {
return SDL_SetTextureColorMod(texture->native, r, g, b);
} else if (renderer->SetTextureColorMod) {
return renderer->SetTextureColorMod(renderer, texture);
} else {
return 0;
}
}
void SDL_UnlockTexture ( SDL_Texture texture)

Unlock a texture, uploading the changes to video memory, if needed.

See Also
SDL_LockTexture()

Definition at line 1181 of file SDL_render.c.

References SDL_Texture::access, CHECK_TEXTURE_MAGIC, SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_TEXTUREACCESS_STREAMING, SDL_UnlockTextureNative(), SDL_UnlockTextureYUV(), SDL_Renderer::UnlockTexture, and SDL_Texture::yuv.

{
CHECK_TEXTURE_MAGIC(texture, );
return;
}
if (texture->yuv) {
} else if (texture->native) {
} else {
renderer = texture->renderer;
renderer->UnlockTexture(renderer, texture);
}
}
int SDL_UpdateTexture ( SDL_Texture texture,
const SDL_Rect rect,
const void pixels,
int  pitch 
)

Update the given texture rectangle with new pixel data.

Parameters
textureThe texture to update
rectA pointer to the rectangle of pixels to update, or NULL to update the entire texture.
pixelsThe raw pixel data in the format of the texture.
pitchThe number of bytes in a row of pixel data, including padding between lines.

The pixel data must be in the format of the texture. The pixel format can be queried with SDL_QueryTexture.

Returns
0 on success, or -1 if the texture is not valid.
Note
This is a fairly slow function.

Definition at line 941 of file SDL_render.c.

References CHECK_TEXTURE_MAGIC, SDL_Texture::h, SDL_Rect::h, SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_InvalidParamError, SDL_UpdateTextureNative(), SDL_UpdateTextureYUV(), SDL_Renderer::UpdateTexture, SDL_Texture::w, SDL_Rect::w, SDL_Rect::x, SDL_Rect::y, and SDL_Texture::yuv.

{
SDL_Rect full_rect;
CHECK_TEXTURE_MAGIC(texture, -1);
if (!pixels) {
return SDL_InvalidParamError("pixels");
}
if (!pitch) {
return SDL_InvalidParamError("pitch");
}
if (!rect) {
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = texture->w;
full_rect.h = texture->h;
rect = &full_rect;
}
if ((rect->w == 0) || (rect->h == 0)) {
return 0; /* nothing to do. */
} else if (texture->yuv) {
return SDL_UpdateTextureYUV(texture, rect, pixels, pitch);
} else if (texture->native) {
return SDL_UpdateTextureNative(texture, rect, pixels, pitch);
} else {
renderer = texture->renderer;
return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
}
}
int SDL_UpdateYUVTexture ( SDL_Texture texture,
const SDL_Rect rect,
const Uint8 Yplane,
int  Ypitch,
const Uint8 Uplane,
int  Upitch,
const Uint8 Vplane,
int  Vpitch 
)

Update a rectangle within a planar YV12 or IYUV texture with new pixel data.

Parameters
textureThe texture to update
rectA pointer to the rectangle of pixels to update, or NULL to update the entire texture.
YplaneThe raw pixel data for the Y plane.
YpitchThe number of bytes between rows of pixel data for the Y plane.
UplaneThe raw pixel data for the U plane.
UpitchThe number of bytes between rows of pixel data for the U plane.
VplaneThe raw pixel data for the V plane.
VpitchThe number of bytes between rows of pixel data for the V plane.
Returns
0 on success, or -1 if the texture is not valid.
Note
You can use SDL_UpdateTexture() as long as your pixel data is a contiguous block of Y and U/V planes in the proper order, but this function is available if your pixel data is not contiguous.

Definition at line 1028 of file SDL_render.c.

References CHECK_TEXTURE_MAGIC, SDL_Texture::format, SDL_Texture::h, SDL_Rect::h, SDL_Texture::native, renderer, SDL_Texture::renderer, SDL_assert, SDL_InvalidParamError, SDL_PIXELFORMAT_IYUV, SDL_PIXELFORMAT_YV12, SDL_SetError, SDL_Unsupported, SDL_UpdateTextureYUVPlanar(), SDL_Renderer::UpdateTextureYUV, SDL_Texture::w, SDL_Rect::w, SDL_Rect::x, SDL_Rect::y, and SDL_Texture::yuv.

{
SDL_Rect full_rect;
CHECK_TEXTURE_MAGIC(texture, -1);
if (!Yplane) {
return SDL_InvalidParamError("Yplane");
}
if (!Ypitch) {
return SDL_InvalidParamError("Ypitch");
}
if (!Uplane) {
return SDL_InvalidParamError("Uplane");
}
if (!Upitch) {
return SDL_InvalidParamError("Upitch");
}
if (!Vplane) {
return SDL_InvalidParamError("Vplane");
}
if (!Vpitch) {
return SDL_InvalidParamError("Vpitch");
}
if (texture->format != SDL_PIXELFORMAT_YV12 &&
return SDL_SetError("Texture format must by YV12 or IYUV");
}
if (!rect) {
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = texture->w;
full_rect.h = texture->h;
rect = &full_rect;
}
if (!rect->w || !rect->h) {
return 0; /* nothing to do. */
}
if (texture->yuv) {
return SDL_UpdateTextureYUVPlanar(texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
} else {
SDL_assert(!texture->native);
renderer = texture->renderer;
if (renderer->UpdateTextureYUV) {
return renderer->UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
} else {
return SDL_Unsupported();
}
}
}