render topic

CategoryRender

Header file for SDL 2D rendering functions.

This API supports the following features:

  • single pixel points
  • single pixel lines
  • filled rectangles
  • texture images
  • 2D polygons

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 3D polygons and particle effects, and in that case you should use SDL's OpenGL/Direct3D support, the SDL3 GPU API, or one of the many good 3D engines.

These functions must be called from the main thread. See this bug for details: https://github.com/libsdl-org/SDL/issues/986

Functions

sdlAddVulkanRenderSemaphores(Pointer<SdlRenderer> renderer, int waitStageMask, int waitSemaphore, int signalSemaphore) bool render
Add a set of synchronization semaphores for the current frame.
sdlConvertEventToRenderCoordinates(Pointer<SdlRenderer> renderer, Pointer<SdlEvent> event) bool render
Convert the coordinates in an event to render coordinates.
sdlCreateGpuRenderer(Pointer<SdlWindow> window, int formatFlags, Pointer<Pointer<SdlGpuDevice>> device) Pointer<SdlRenderer> render
Create a 2D GPU rendering context for a window, with support for the specified shader format.
sdlCreateGpuRenderState(Pointer<SdlRenderer> renderer, Pointer<SdlGpuRenderStateCreateInfo> createinfo) Pointer<SdlGpuRenderState> render
Create custom GPU render state.
sdlCreateRenderer(Pointer<SdlWindow> window, String? name) Pointer<SdlRenderer> render
Create a 2D rendering context for a window.
sdlCreateRendererWithProperties(int props) Pointer<SdlRenderer> render
Create a 2D rendering context for a window, with the specified properties.
sdlCreateSoftwareRenderer(Pointer<SdlSurface> surface) Pointer<SdlRenderer> render
Create a 2D software rendering context for a surface.
sdlCreateTexture(Pointer<SdlRenderer> renderer, int format, int access, int w, int h) Pointer<SdlTexture> render
Create a texture for a rendering context.
sdlCreateTextureFromSurface(Pointer<SdlRenderer> renderer, Pointer<SdlSurface> surface) Pointer<SdlTexture> render
Create a texture from an existing surface.
sdlCreateTextureWithProperties(Pointer<SdlRenderer> renderer, int props) Pointer<SdlTexture> render
Create a texture for a rendering context with the specified properties.
sdlCreateWindowAndRenderer(String? title, int width, int height, int windowFlags, Pointer<Pointer<SdlWindow>> window, Pointer<Pointer<SdlRenderer>> renderer) bool render
Create a window and default renderer.
sdlDestroyGpuRenderState(Pointer<SdlGpuRenderState> state) → void render
Destroy custom GPU render state.
sdlDestroyRenderer(Pointer<SdlRenderer> renderer) → void render
Destroy the rendering context for a window and free all associated textures.
sdlDestroyTexture(Pointer<SdlTexture> texture) → void render
Destroy the specified texture.
sdlFlushRenderer(Pointer<SdlRenderer> renderer) bool render
Force the rendering context to flush any pending commands and state.
sdlGetCurrentRenderOutputSize(Pointer<SdlRenderer> renderer, Pointer<Int32> w, Pointer<Int32> h) bool render
Get the current output size in pixels of a rendering context.
sdlGetDefaultTextureScaleMode(Pointer<SdlRenderer> renderer, Pointer<Int32> scaleMode) bool render
Get default texture scale mode of the given renderer.
sdlGetNumRenderDrivers() int render
Get the number of 2D rendering drivers available for the current display.
sdlGetRenderClipRect(Pointer<SdlRenderer> renderer, Pointer<SdlRect> rect) bool render
Get the clip rectangle for the current target.
sdlGetRenderColorScale(Pointer<SdlRenderer> renderer, Pointer<Float> scale) bool render
Get the color scale used for render operations.
sdlGetRenderDrawBlendMode(Pointer<SdlRenderer> renderer, Pointer<Uint32> blendMode) bool render
Get the blend mode used for drawing operations.
sdlGetRenderDrawColor(Pointer<SdlRenderer> renderer, Pointer<Uint8> r, Pointer<Uint8> g, Pointer<Uint8> b, Pointer<Uint8> a) bool render
Get the color used for drawing operations (Rect, Line and Clear).
sdlGetRenderDrawColorFloat(Pointer<SdlRenderer> renderer, Pointer<Float> r, Pointer<Float> g, Pointer<Float> b, Pointer<Float> a) bool render
Get the color used for drawing operations (Rect, Line and Clear).
sdlGetRenderDriver(int index) String? render
Use this function to get the name of a built in 2D rendering driver.
sdlGetRenderer(Pointer<SdlWindow> window) Pointer<SdlRenderer> render
Get the renderer associated with a window.
sdlGetRendererFromTexture(Pointer<SdlTexture> texture) Pointer<SdlRenderer> render
Get the renderer that created an SDL_Texture.
sdlGetRendererName(Pointer<SdlRenderer> renderer) String? render
Get the name of a renderer.
sdlGetRendererProperties(Pointer<SdlRenderer> renderer) int render
Get the properties associated with a renderer.
sdlGetRenderLogicalPresentation(Pointer<SdlRenderer> renderer, Pointer<Int32> w, Pointer<Int32> h, Pointer<Int32> mode) bool render
Get device independent resolution and presentation mode for rendering.
sdlGetRenderLogicalPresentationRect(Pointer<SdlRenderer> renderer, Pointer<SdlFRect> rect) bool render
Get the final presentation rectangle for rendering.
sdlGetRenderMetalCommandEncoder(Pointer<SdlRenderer> renderer) Pointer<NativeType> render
Get the Metal command encoder for the current frame.
sdlGetRenderMetalLayer(Pointer<SdlRenderer> renderer) Pointer<NativeType> render
Get the CAMetalLayer associated with the given Metal renderer.
sdlGetRenderOutputSize(Pointer<SdlRenderer> renderer, Pointer<Int32> w, Pointer<Int32> h) bool render
Get the output size in pixels of a rendering context.
sdlGetRenderSafeArea(Pointer<SdlRenderer> renderer, Pointer<SdlRect> rect) bool render
Get the safe area for rendering within the current viewport.
sdlGetRenderScale(Pointer<SdlRenderer> renderer, Pointer<Float> scaleX, Pointer<Float> scaleY) bool render
Get the drawing scale for the current target.
sdlGetRenderTarget(Pointer<SdlRenderer> renderer) Pointer<SdlTexture> render
Get the current render target.
sdlGetRenderTextureAddressMode(Pointer<SdlRenderer> renderer, Pointer<Int32> uMode, Pointer<Int32> vMode) bool render
Get the texture addressing mode used in SDL_RenderGeometry().
sdlGetRenderViewport(Pointer<SdlRenderer> renderer, Pointer<SdlRect> rect) bool render
Get the drawing area for the current target.
sdlGetRenderVSync(Pointer<SdlRenderer> renderer, Pointer<Int32> vsync) bool render
Get VSync of the given renderer.
sdlGetRenderWindow(Pointer<SdlRenderer> renderer) Pointer<SdlWindow> render
Get the window associated with a renderer.
sdlGetTextureAlphaMod(Pointer<SdlTexture> texture, Pointer<Uint8> alpha) bool render
Get the additional alpha value multiplied into render copy operations.
sdlGetTextureAlphaModFloat(Pointer<SdlTexture> texture, Pointer<Float> alpha) bool render
Get the additional alpha value multiplied into render copy operations.
sdlGetTextureBlendMode(Pointer<SdlTexture> texture, Pointer<Uint32> blendMode) bool render
Get the blend mode used for texture copy operations.
sdlGetTextureColorMod(Pointer<SdlTexture> texture, Pointer<Uint8> r, Pointer<Uint8> g, Pointer<Uint8> b) bool render
Get the additional color value multiplied into render copy operations.
sdlGetTextureColorModFloat(Pointer<SdlTexture> texture, Pointer<Float> r, Pointer<Float> g, Pointer<Float> b) bool render
Get the additional color value multiplied into render copy operations.
sdlGetTextureProperties(Pointer<SdlTexture> texture) int render
Get the properties associated with a texture.
sdlGetTextureScaleMode(Pointer<SdlTexture> texture, Pointer<Int32> scaleMode) bool render
Get the scale mode used for texture scale operations.
sdlGetTextureSize(Pointer<SdlTexture> texture, Pointer<Float> w, Pointer<Float> h) bool render
Get the size of a texture, as floating point values.
sdlLockTexture(Pointer<SdlTexture> texture, Pointer<SdlRect> rect, Pointer<Pointer<NativeType>> pixels, Pointer<Int32> pitch) bool render
Lock a portion of the texture for write-only pixel access.
sdlLockTextureToSurface(Pointer<SdlTexture> texture, Pointer<SdlRect> rect, Pointer<Pointer<SdlSurface>> surface) bool render
Lock a portion of the texture for write-only pixel access, and expose it as a SDL surface.
sdlRenderClear(Pointer<SdlRenderer> renderer) bool render
Clear the current rendering target with the drawing color.
sdlRenderClipEnabled(Pointer<SdlRenderer> renderer) bool render
Get whether clipping is enabled on the given render target.
sdlRenderCoordinatesFromWindow(Pointer<SdlRenderer> renderer, double windowX, double windowY, Pointer<Float> x, Pointer<Float> y) bool render
Get a point in render coordinates when given a point in window coordinates.
sdlRenderCoordinatesToWindow(Pointer<SdlRenderer> renderer, double x, double y, Pointer<Float> windowX, Pointer<Float> windowY) bool render
Get a point in window coordinates when given a point in render coordinates.
sdlRenderDebugText(Pointer<SdlRenderer> renderer, double x, double y, String? str) bool render
Draw debug text to an SDL_Renderer.
sdlRenderDebugTextFormat(Pointer<SdlRenderer> renderer, double x, double y, String? fmt) bool render
Draw debug text to an SDL_Renderer.
sdlRenderFillRect(Pointer<SdlRenderer> renderer, Pointer<SdlFRect> rect) bool render
Fill a rectangle on the current rendering target with the drawing color at subpixel precision.
sdlRenderFillRects(Pointer<SdlRenderer> renderer, Pointer<SdlFRect> rects, int count) bool render
Fill some number of rectangles on the current rendering target with the drawing color at subpixel precision.
sdlRenderGeometry(Pointer<SdlRenderer> renderer, Pointer<SdlTexture> texture, Pointer<SdlVertex> vertices, int numVertices, Pointer<Int32> indices, int numIndices) bool render
Render a list of triangles, optionally using a texture and indices into the vertex array Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
sdlRenderGeometryRaw(Pointer<SdlRenderer> renderer, Pointer<SdlTexture> texture, Pointer<Float> xy, int xyStride, Pointer<SdlFColor> color, int colorStride, Pointer<Float> uv, int uvStride, int numVertices, Pointer<NativeType> indices, int numIndices, int sizeIndices) bool render
Render a list of triangles, optionally using a texture and indices into the vertex arrays Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
sdlRenderLine(Pointer<SdlRenderer> renderer, double x1, double y1, double x2, double y2) bool render
Draw a line on the current rendering target at subpixel precision.
sdlRenderLines(Pointer<SdlRenderer> renderer, Pointer<SdlFPoint> points, int count) bool render
Draw a series of connected lines on the current rendering target at subpixel precision.
sdlRenderPoint(Pointer<SdlRenderer> renderer, double x, double y) bool render
Draw a point on the current rendering target at subpixel precision.
sdlRenderPoints(Pointer<SdlRenderer> renderer, Pointer<SdlFPoint> points, int count) bool render
Draw multiple points on the current rendering target at subpixel precision.
sdlRenderPresent(Pointer<SdlRenderer> renderer) bool render
Update the screen with any rendering performed since the previous call.
sdlRenderReadPixels(Pointer<SdlRenderer> renderer, Pointer<SdlRect> rect) Pointer<SdlSurface> render
Read pixels from the current rendering target.
sdlRenderRect(Pointer<SdlRenderer> renderer, Pointer<SdlFRect> rect) bool render
Draw a rectangle on the current rendering target at subpixel precision.
sdlRenderRects(Pointer<SdlRenderer> renderer, Pointer<SdlFRect> rects, int count) bool render
Draw some number of rectangles on the current rendering target at subpixel precision.
sdlRenderTexture(Pointer<SdlRenderer> renderer, Pointer<SdlTexture> texture, Pointer<SdlFRect> srcrect, Pointer<SdlFRect> dstrect) bool render
Copy a portion of the texture to the current rendering target at subpixel precision.
sdlRenderTexture9Grid(Pointer<SdlRenderer> renderer, Pointer<SdlTexture> texture, Pointer<SdlFRect> srcrect, double leftWidth, double rightWidth, double topHeight, double bottomHeight, double scale, Pointer<SdlFRect> dstrect) bool render
Perform a scaled copy using the 9-grid algorithm to the current rendering target at subpixel precision.
sdlRenderTexture9GridTiled(Pointer<SdlRenderer> renderer, Pointer<SdlTexture> texture, Pointer<SdlFRect> srcrect, double leftWidth, double rightWidth, double topHeight, double bottomHeight, double scale, Pointer<SdlFRect> dstrect, double tileScale) bool render
Perform a scaled copy using the 9-grid algorithm to the current rendering target at subpixel precision.
sdlRenderTextureAffine(Pointer<SdlRenderer> renderer, Pointer<SdlTexture> texture, Pointer<SdlFRect> srcrect, Pointer<SdlFPoint> origin, Pointer<SdlFPoint> right, Pointer<SdlFPoint> down) bool render
Copy a portion of the source texture to the current rendering target, with affine transform, at subpixel precision.
sdlRenderTextureRotated(Pointer<SdlRenderer> renderer, Pointer<SdlTexture> texture, Pointer<SdlFRect> srcrect, Pointer<SdlFRect> dstrect, double angle, Pointer<SdlFPoint> center, int flip) bool render
Copy a portion of the source texture to the current rendering target, with rotation and flipping, at subpixel precision.
sdlRenderTextureTiled(Pointer<SdlRenderer> renderer, Pointer<SdlTexture> texture, Pointer<SdlFRect> srcrect, double scale, Pointer<SdlFRect> dstrect) bool render
Tile a portion of the texture to the current rendering target at subpixel precision.
sdlRenderViewportSet(Pointer<SdlRenderer> renderer) bool render
Return whether an explicit rectangle was set as the viewport.
sdlSetDefaultTextureScaleMode(Pointer<SdlRenderer> renderer, int scaleMode) bool render
Set default scale mode for new textures for given renderer.
sdlSetGpuRenderStateFragmentUniforms(Pointer<SdlGpuRenderState> state, int slotIndex, Pointer<NativeType> data, int length) bool render
Set fragment shader uniform variables in a custom GPU render state.
sdlSetRenderClipRect(Pointer<SdlRenderer> renderer, Pointer<SdlRect> rect) bool render
Set the clip rectangle for rendering on the specified target.
sdlSetRenderColorScale(Pointer<SdlRenderer> renderer, double scale) bool render
Set the color scale used for render operations.
sdlSetRenderDrawBlendMode(Pointer<SdlRenderer> renderer, int blendMode) bool render
Set the blend mode used for drawing operations (Fill and Line).
sdlSetRenderDrawColor(Pointer<SdlRenderer> renderer, int r, int g, int b, int a) bool render
Set the color used for drawing operations.
sdlSetRenderDrawColorFloat(Pointer<SdlRenderer> renderer, double r, double g, double b, double a) bool render
Set the color used for drawing operations (Rect, Line and Clear).
sdlSetRenderGpuState(Pointer<SdlRenderer> renderer, Pointer<SdlGpuRenderState> state) bool render
Set custom GPU render state.
sdlSetRenderLogicalPresentation(Pointer<SdlRenderer> renderer, int w, int h, int mode) bool render
Set a device-independent resolution and presentation mode for rendering.
sdlSetRenderScale(Pointer<SdlRenderer> renderer, double scaleX, double scaleY) bool render
Set the drawing scale for rendering on the current target.
sdlSetRenderTarget(Pointer<SdlRenderer> renderer, Pointer<SdlTexture> texture) bool render
Set a texture as the current rendering target.
sdlSetRenderTextureAddressMode(Pointer<SdlRenderer> renderer, int uMode, int vMode) bool render
Set the texture addressing mode used in SDL_RenderGeometry().
sdlSetRenderViewport(Pointer<SdlRenderer> renderer, Pointer<SdlRect> rect) bool render
Set the drawing area for rendering on the current target.
sdlSetRenderVSync(Pointer<SdlRenderer> renderer, int vsync) bool render
Toggle VSync of the given renderer.
sdlSetTextureAlphaMod(Pointer<SdlTexture> texture, int alpha) bool render
Set an additional alpha value multiplied into render copy operations.
sdlSetTextureAlphaModFloat(Pointer<SdlTexture> texture, double alpha) bool render
Set an additional alpha value multiplied into render copy operations.
sdlSetTextureBlendMode(Pointer<SdlTexture> texture, int blendMode) bool render
Set the blend mode for a texture, used by SDL_RenderTexture().
sdlSetTextureColorMod(Pointer<SdlTexture> texture, int r, int g, int b) bool render
Set an additional color value multiplied into render copy operations.
sdlSetTextureColorModFloat(Pointer<SdlTexture> texture, double r, double g, double b) bool render
Set an additional color value multiplied into render copy operations.
sdlSetTextureScaleMode(Pointer<SdlTexture> texture, int scaleMode) bool render
Set the scale mode used for texture scale operations.
sdlUnlockTexture(Pointer<SdlTexture> texture) → void render
Unlock a texture, uploading the changes to video memory, if needed.
sdlUpdateNvTexture(Pointer<SdlTexture> texture, Pointer<SdlRect> rect, Pointer<Uint8> yplane, int ypitch, Pointer<Uint8> uVplane, int uVpitch) bool render
Update a rectangle within a planar NV12 or NV21 texture with new pixels.
sdlUpdateTexture(Pointer<SdlTexture> texture, Pointer<SdlRect> rect, Pointer<NativeType> pixels, int pitch) bool render
Update the given texture rectangle with new pixel data.
sdlUpdateYuvTexture(Pointer<SdlTexture> texture, Pointer<SdlRect> rect, Pointer<Uint8> yplane, int ypitch, Pointer<Uint8> uplane, int upitch, Pointer<Uint8> vplane, int vpitch) bool render
Update a rectangle within a planar YV12 or IYUV texture with new pixel data.