SDL3pp
A slim C++ wrapper for SDL3
|
A structure representing rendering state. More...
Public Member Functions | |
RendererBase (WindowRef window) | |
Create a 2D rendering context for a window. | |
RendererBase (WindowBase &window, StringParam name) | |
Create a 2D rendering context for a window. | |
RendererBase (PropertiesBase &props) | |
Create a 2D rendering context for a window, with the specified properties. | |
RendererBase (SurfaceBase &surface) | |
Create a 2D software rendering context for a surface. | |
WindowRef | GetWindow () |
Get the window associated with a renderer. | |
const char * | GetName () const |
Get the name of a renderer. | |
Point | GetOutputSize () const |
Get the output size in pixels of a rendering context. | |
void | GetOutputSize (int *w, int *h) const |
Get the output size in pixels of a rendering context. | |
Point | GetCurrentOutputSize () const |
Get the current output size in pixels of a rendering context. | |
void | GetCurrentOutputSize (int *w, int *h) const |
Get the current output size in pixels of a rendering context. | |
PropertiesRef | GetProperties () const |
Get the properties associated with a renderer. | |
void | ResetTarget () |
Set target texture back to window. | |
void | SetTarget (OptionalTexture texture) |
Set a texture as the current rendering target. | |
TextureRef | GetTarget () const |
Get the current render target. | |
void | SetLogicalPresentation (SDL_Point size, RendererLogicalPresentation mode) |
Set a device-independent resolution and presentation mode for rendering. | |
void | GetLogicalPresentation (SDL_Point *size, RendererLogicalPresentation *mode) |
Get device independent resolution and presentation mode for rendering. | |
void | GetLogicalPresentation (int *w, int *h, RendererLogicalPresentation *mode) const |
Get device independent resolution and presentation mode for rendering. | |
FRect | GetLogicalPresentationRect () const |
Get the final presentation rectangle for rendering. | |
FPoint | RenderCoordinatesFromWindow (const SDL_FPoint &window_coord) const |
Get a point in render coordinates when given a point in window coordinates. | |
FPoint | RenderCoordinatesToWindow (const SDL_FPoint &coord) const |
Get a point in window coordinates when given a point in render coordinates. | |
void | ConvertEventToRenderCoordinates (Event *event) const |
Convert the coordinates in an event to render coordinates. | |
void | ResetViewport () |
Reset the drawing area for rendering to the entire target. | |
void | SetViewport (OptionalRef< const SDL_Rect > rect) |
Set the drawing area for rendering on the current target. | |
Rect | GetViewport () const |
Get the drawing area for the current target. | |
bool | IsViewportSet () const |
Return whether an explicit rectangle was set as the viewport. | |
Rect | GetSafeArea () const |
Get the safe area for rendering within the current viewport. | |
void | ResetClipRect () |
Reset the clip rectangle for rendering to the entire render target. | |
void | SetClipRect (OptionalRef< const SDL_Rect > rect) |
Set the clip rectangle for rendering on the specified target. | |
Rect | GetClipRect () const |
Get the clip rectangle for the current target. | |
bool | IsClipEnabled () const |
Get whether clipping is enabled on the given render target. | |
void | SetScale (SDL_FPoint scale) |
Set the drawing scale for rendering on the current target. | |
FPoint | GetScale () const |
Get the drawing scale for the current target. | |
void | GetScale (float *scaleX, float *scaleY) const |
Get the drawing scale for the current target. | |
void | SetDrawColor (SDL_Color c) |
Set the color used for drawing operations. | |
void | SetDrawColor (SDL_FColor c) |
Set the color used for drawing operations (Rect, Line and Clear). | |
FColor | GetDrawColor () const |
Get the color used for drawing operations (Rect, Line and Clear). | |
void | GetDrawColor (SDL_Color *c) const |
Get the color used for drawing operations (Rect, Line and Clear). | |
void | GetDrawColor (SDL_FColor *c) const |
Get the color used for drawing operations (Rect, Line and Clear). | |
void | GetDrawColor (Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) const |
Get the color used for drawing operations (Rect, Line and Clear). | |
void | GetDrawColor (float *r, float *g, float *b, float *a) const |
Get the color used for drawing operations (Rect, Line and Clear). | |
void | SetColorScale (float scale) |
Set the color scale used for render operations. | |
float | GetColorScale () const |
Get the color scale used for render operations. | |
void | SetDrawBlendMode (BlendMode blendMode) |
Set the blend mode used for drawing operations (Fill and Line). | |
BlendMode | GetDrawBlendMode () const |
Get the blend mode used for drawing operations. | |
void | RenderClear () |
Clear the current rendering target with the drawing color. | |
void | RenderPoint (SDL_FPoint p) |
Draw a point on the current rendering target at subpixel precision. | |
void | RenderPoints (SpanRef< const SDL_FPoint > points) |
Draw multiple points on the current rendering target at subpixel precision. | |
void | RenderLine (SDL_FPoint p1, SDL_FPoint p2) |
Draw a line on the current rendering target at subpixel precision. | |
void | RenderLines (SpanRef< const SDL_FPoint > points) |
Draw a series of connected lines on the current rendering target at subpixel precision. | |
void | RenderRect (OptionalRef< const SDL_FRect > rect) |
Draw a rectangle on the current rendering target at subpixel precision. | |
void | RenderRects (SpanRef< const SDL_FRect > rects) |
Draw some number of rectangles on the current rendering target at subpixel precision. | |
void | RenderFillRect (OptionalRef< const SDL_FRect > rect) |
Fill a rectangle on the current rendering target with the drawing color at subpixel precision. | |
void | RenderFillRects (SpanRef< const SDL_FRect > rects) |
Fill some number of rectangles on the current rendering target with the drawing color at subpixel precision. | |
void | RenderTexture (TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, OptionalRef< const SDL_FRect > dstrect) |
Copy a portion of the texture to the current rendering target at subpixel precision. | |
void | RenderTextureRotated (TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, OptionalRef< const SDL_FRect > dstrect, double angle, OptionalRef< const SDL_FPoint > center={}, FlipMode flip=SDL_FLIP_NONE) |
Copy a portion of the source texture to the current rendering target, with rotation and flipping, at subpixel precision. | |
void | RenderTextureAffine (TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, OptionalRef< const SDL_FPoint > origin, OptionalRef< const SDL_FPoint > right, OptionalRef< const SDL_FPoint > down) |
Copy a portion of the source texture to the current rendering target, with affine transform, at subpixel precision. | |
void | RenderTextureTiled (TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, float scale, OptionalRef< const SDL_FRect > dstrect) |
Tile a portion of the texture to the current rendering target at subpixel precision. | |
void | RenderTexture9Grid (TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, OptionalRef< const SDL_FRect > dstrect) |
Perform a scaled copy using the 9-grid algorithm to the current rendering target at subpixel precision. | |
void | RenderGeometry (OptionalTexture texture, std::span< const Vertex > vertices, std::span< const int > indices={}) |
Render a list of triangles, optionally using a texture and indices into the vertex array Color and alpha modulation is done per vertex (TextureBase.SetColorMod and TextureBase.SetAlphaMod are ignored). | |
void | RenderGeometryRaw (OptionalTexture texture, const float *xy, int xy_stride, const FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices) |
Render a list of triangles, optionally using a texture and indices into the vertex arrays Color and alpha modulation is done per vertex (TextureBase.SetColorMod and TextureBase.SetAlphaMod are ignored). | |
Surface | ReadPixels (OptionalRef< const SDL_Rect > rect={}) const |
Read pixels from the current rendering target. | |
void | Present () |
Update the screen with any rendering performed since the previous call. | |
void | Flush () |
Force the rendering context to flush any pending commands and state. | |
void | SetVSync (int vsync) |
Toggle VSync of the given renderer. | |
int | GetVSync () const |
Get VSync of the given renderer. | |
void | RenderDebugText (FPoint p, StringParam str) |
Draw debug text to an RendererBase. | |
template<class... ARGS> | |
void | RenderDebugTextFormat (FPoint p, std::string_view fmt, ARGS... args) |
Draw debug text to an SDL_Renderer. | |
constexpr | Resource (T resource={}) |
Constructs the underlying resource. | |
constexpr | Resource (std::nullptr_t) |
Equivalent to default ctor. | |
constexpr | Resource (std::nullopt_t) |
Equivalent to default ctor. | |
Resource (const Resource &other)=delete | |
Resource (Resource &&other)=delete | |
![]() | |
constexpr | Resource (SDL_Renderer * resource={}) |
Constructs the underlying resource. | |
constexpr | Resource (std::nullptr_t) |
Equivalent to default ctor. | |
constexpr | Resource (std::nullopt_t) |
Equivalent to default ctor. | |
Resource (const Resource &other)=delete | |
Resource (Resource &&other)=delete | |
Resource & | operator= (const Resource &other)=delete |
Resource & | operator= (Resource &&other)=delete |
constexpr | operator bool () const |
True if contains a valid resource. | |
constexpr bool | operator== (const Resource &other) const=default |
Comparison. | |
constexpr bool | operator== (std::nullopt_t) const |
Comparison. | |
constexpr bool | operator== (std::nullptr_t) const |
Comparison. | |
constexpr SDL_Renderer * | get () const |
Return contained resource;. | |
constexpr SDL_Renderer * | release (SDL_Renderer * newResource={}) |
Return contained resource and empties or replace value. | |
constexpr const SDL_Renderer * | operator-> () const |
Access to fields. | |
constexpr SDL_Renderer * | operator-> () |
Access to fields. | |
|
inline |
By default the rendering size matches the window size in pixels, but you can call SDL_SetRenderLogicalPresentation() to change the content size and scaling options.
It renderer creation fails for any reason this object is falsy; call GetError() for more information.
window | the window where rendering is displayed. |
|
inline |
If you want a specific renderer, you can specify its name here. A list of available renderers can be obtained by calling GetRenderDriver() multiple times, with indices from 0 to GetNumRenderDrivers()-1. If you don't need a specific renderer, specify nullptr and SDL will attempt to choose the best option for you, based on what is available on the user's system.
If name
is a comma-separated list, SDL will try each name, in the order listed, until one succeeds or all of them fail.
By default the rendering size matches the window size in pixels, but you can call RendererBase.SetLogicalPresentation() to change the content size and scaling options.
It renderer creation fails for any reason this object is falsy; call GetError() for more information.
window | the window where rendering is displayed. |
name | the name of the rendering driver to initialize, or nullptr to let SDL choose one. |
Error | on failure. |
|
inline |
These are the supported properties:
prop::Renderer.CREATE_NAME_STRING
: the name of the rendering driver to use, if a specific one is desiredprop::Renderer.CREATE_WINDOW_POINTER
: the window where rendering is displayed, required if this isn't a software renderer using a surfaceprop::Renderer.CREATE_SURFACE_POINTER
: the surface where rendering is displayed, if you want a software renderer without a windowprop::Renderer.CREATE_OUTPUT_COLORSPACE_NUMBER
: an Colorspace value describing the colorspace for output to the display, defaults to COLORSPACE_SRGB. The direct3d11, direct3d12, and metal renderers support COLORSPACE_SRGB_LINEAR, which is a linear color space and supports HDR output. If you select COLORSPACE_SRGB_LINEAR, drawing still uses the sRGB colorspace, but values can go beyond 1.0 and float (linear) format textures can be used for HDR content.prop::Renderer.CREATE_PRESENT_VSYNC_NUMBER
: non-zero if you want present synchronized with the refresh rate. This property can take any value that is supported by RendererBase.SetVSync() for the renderer.With the vulkan renderer:
prop::Renderer.CREATE_VULKAN_INSTANCE_POINTER
: the VkInstance to use with the renderer, optional.prop::Renderer.CREATE_VULKAN_SURFACE_NUMBER
: the VkSurfaceKHR to use with the renderer, optional.prop::Renderer.CREATE_VULKAN_PHYSICAL_DEVICE_POINTER
: the VkPhysicalDevice to use with the renderer, optional.prop::Renderer.CREATE_VULKAN_DEVICE_POINTER
: the VkDevice to use with the renderer, optional.prop::Renderer.CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER
: the queue family index used for rendering.prop::Renderer.CREATE_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER
: the queue family index used for presentation.It renderer creation fails for any reason this object is falsy; call GetError() for more information.
props | the properties to use. |
Error | on failure. |
|
inline |
Two other API which can be used to create RendererBase: RendererBase.RendererBase() and CreateWindowAndRenderer(). These can also create a software renderer, but they are intended to be used with an WindowBase as the final destination and not an SurfaceBase.
surface | the Surface structure representing the surface where rendering is done. |
Error | on failure. |
|
inline |
This takes into account several states:
Various event types are converted with this function: mouse, touch, pen, etc.
Touch coordinates are converted from normalized coordinates in the window to non-normalized rendering coordinates.
Relative mouse coordinates (xrel and yrel event fields) are also converted. Applications that do not want these fields converted should use RendererBase.RenderCoordinatesFromWindow() on the specific event fields instead of converting the entire event structure.
Once converted, coordinates may be outside the rendering area.
event | the event to modify. |
Error | on failure. |
|
inline |
You do not need to (and in fact, shouldn't) call this function unless you are planning to call into OpenGL/Direct3D/Metal/whatever directly, in addition to using an RendererBase.
This is for a very-specific case: if you are using SDL's render API, and you plan to make OpenGL/D3D/whatever calls in addition to SDL render API calls. If this applies, you should call this function between calls to SDL's render API and the low-level API you're using in cooperation.
In all other cases, you can ignore this function.
This call makes SDL flush any pending rendering work it was queueing up to do later in a single batch, and marks any internal cached state as invalid, so it'll prepare all its state again later, from scratch.
This means you do not need to save state in your rendering code to protect the SDL renderer. However, there lots of arbitrary pieces of Direct3D and OpenGL state that can confuse things; you should use your best judgment and be prepared to make changes if specific state needs to be protected.
Error | on failure. |
|
inline |
Each render target has its own clip rectangle. This function gets the cliprect for the current render target.
Error | on failure. |
|
inline |
Error | on failure. |
|
inline |
If a rendering target is active, this will return the size of the rendering target in pixels, otherwise if a logical size is set, it will return the logical size, otherwise it will return the value of GetOutputSize().
Error | on failure. |
|
inline |
If a rendering target is active, this will return the size of the rendering target in pixels, otherwise return the value of RendererBase.GetOutputSize().
Rendering target or not, the output will be adjusted by the current logical presentation state, dictated by RendererBase.SetLogicalPresentation().
w | a pointer filled in with the current width. |
h | a pointer filled in with the current height. |
Error | on failure. |
|
inline |
Error | on failure. |
|
inline |
Error | on failure. |
|
inline |
r | a pointer filled in with the red value used to draw on the rendering target. |
g | a pointer filled in with the green value used to draw on the rendering target. |
b | a pointer filled in with the blue value used to draw on the rendering target. |
a | a pointer filled in with the alpha value used to draw on the rendering target. |
Error | on failure. |
|
inline |
c | a pointer filled in with the color channel values used to draw on the rendering target. must not be nullptr. |
Error | on failure. |
|
inline |
c | a pointer filled in with the color channel values used to draw on the rendering target. must not be nullptr. |
Error | on failure. |
|
inline |
r | a pointer filled in with the red value used to draw on the rendering target. |
g | a pointer filled in with the green value used to draw on the rendering target. |
b | a pointer filled in with the blue value used to draw on the rendering target. |
a | a pointer filled in with the alpha value used to draw on the rendering target; usually SDL_ALPHA_OPAQUE (255). |
Error | on failure. |
|
inline |
This function gets the width and height of the logical rendering output, or the output size in pixels if a logical resolution is not enabled.
Each render target has its own logical presentation state. This function gets the state for the current render target.
w | an int to be filled with the width. |
h | an int to be filled with the height. |
mode | the presentation mode used. |
Error | on failure. |
|
inline |
This function gets the width and height of the logical rendering output, or the output size in pixels if a logical resolution is not enabled.
size | a Point to be filled with the width and height. |
mode | the presentation mode used. |
Error | on failure. |
|
inline |
This function returns the calculated rectangle used for logical presentation, based on the presentation mode and output size. If logical presentation is disabled, it will fill the rectangle with the output size, in pixels.
Each render target has its own logical presentation state. This function gets the rectangle for the current render target.
Error | on failure. |
|
inline |
|
inline |
This returns the true output size in pixels, ignoring any render targets or logical size and presentation.
|
inline |
This returns the true output size in pixels, ignoring any render targets or logical size and presentation.
For the output size of the current rendering target, with logical size adjustments, use RendererBase.GetCurrentOutputSize() instead.
w | a pointer filled in with the width in pixels. |
h | a pointer filled in with the height in pixels. |
Error | on failure. |
|
inline |
The following read-only properties are provided by SDL:
prop::Renderer.NAME_STRING
: the name of the rendering driverprop::Renderer.WINDOW_POINTER
: the window where rendering is displayed, if anyprop::Renderer.SURFACE_POINTER
: the surface where rendering is displayed, if this is a software renderer without a windowprop::Renderer.VSYNC_NUMBER
: the current vsync settingprop::Renderer.MAX_TEXTURE_SIZE_NUMBER
: the maximum texture width and heightprop::Renderer.TEXTURE_FORMATS_POINTER
: a (const PixelFormat *) array of pixel formats, terminated with PIXELFORMAT_UNKNOWN, representing the available texture formats for this renderer.prop::Renderer.OUTPUT_COLORSPACE_NUMBER
: an Colorspace value describing the colorspace for output to the display, defaults to COLORSPACE_SRGB.prop::Renderer.HDR_ENABLED_BOOLEAN
: true if the output colorspace is COLORSPACE_SRGB_LINEAR and the renderer is showing on a display with HDR enabled. This property can change dynamically when EVENT_WINDOW_HDR_STATE_CHANGED is sent.prop::Renderer.SDR_WHITE_POINT_FLOAT
: the value of SDR white in the COLORSPACE_SRGB_LINEAR colorspace. When HDR is enabled, this value is automatically multiplied into the color scale. This property can change dynamically when EVENT_WINDOW_HDR_STATE_CHANGED is sent.prop::Renderer.HDR_HEADROOM_FLOAT
: the additional high dynamic range that can be displayed, in terms of the SDR white point. When HDR is not enabled, this will be 1.0. This property can change dynamically when EVENT_WINDOW_HDR_STATE_CHANGED is sent.With the direct3d renderer:
prop::Renderer.D3D9_DEVICE_POINTER
: the IDirect3DDevice9 associated with the rendererWith the direct3d11 renderer:
prop::Renderer.D3D11_DEVICE_POINTER
: the ID3D11Device associated with the rendererprop::Renderer.D3D11_SWAPCHAIN_POINTER
: the IDXGISwapChain1 associated with the renderer. This may change when the window is resized.With the direct3d12 renderer:
prop::Renderer.D3D12_DEVICE_POINTER
: the ID3D12Device associated with the rendererprop::Renderer.D3D12_SWAPCHAIN_POINTER
: the IDXGISwapChain4 associated with the renderer.prop::Renderer.D3D12_COMMAND_QUEUE_POINTER
: the ID3D12CommandQueue associated with the rendererWith the vulkan renderer:
prop::Renderer.VULKAN_INSTANCE_POINTER
: the VkInstance associated with the rendererprop::Renderer.VULKAN_SURFACE_NUMBER
: the VkSurfaceKHR associated with the rendererprop::Renderer.VULKAN_PHYSICAL_DEVICE_POINTER
: the VkPhysicalDevice associated with the rendererprop::Renderer.VULKAN_DEVICE_POINTER
: the VkDevice associated with the rendererprop::Renderer.VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER
: the queue family index used for renderingprop::Renderer.VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER
: the queue family index used for presentationprop::Renderer.VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER
: the number of swapchain images, or potential frames in flight, used by the Vulkan rendererWith the gpu renderer:
prop::Renderer.GPU_DEVICE_POINTER
: the SDL_GPUDevice associated with the rendererError | on failure. |
|
inline |
Some devices have portions of the screen which are partially obscured or not interactive, possibly due to on-screen controls, curved edges, camera notches, TV overscan, etc. This function provides the area of the current viewport which is safe to have interactible content. You should continue rendering into the rest of the render target, but it should not contain visually important or interactible content.
Error | on failure. |
|
inline |
Each render target has its own scale. This function gets the scale for the current render target.
Error | on failure. |
|
inline |
Each render target has its own scale. This function gets the scale for the current render target.
scaleX | a pointer filled in with the horizontal scaling factor. |
scaleY | a pointer filled in with the vertical scaling factor. |
Error | on failure. |
|
inline |
|
inline |
Error | on failure. |
|
inline |
|
inline |
Each render target has its own clip rectangle. This function checks the cliprect for the current render target.
|
inline |
This is useful if you're saving and restoring the viewport and want to know whether you should restore a specific rectangle or nullptr.
Each render target has its own viewport. This function checks the viewport for the current render target.
|
inline |
SDL's rendering functions operate on a backbuffer; that is, calling a rendering function such as RendererBase.RenderLine() does not directly put a line on the screen, but rather updates the backbuffer. As such, you compose your entire scene and present the composed backbuffer to the screen as a complete picture.
Therefore, when using SDL's rendering API, one does all drawing intended for the frame, and then calls this function once per frame to present the final drawing to the user.
The backbuffer should be considered invalidated after each present; do not assume that previous contents will exist between frames. You are strongly encouraged to call RendererBase.RenderClear() to initialize the backbuffer before starting each new frame's drawing, even if you plan to overwrite every pixel.
Please note, that in case of rendering to a texture - there is no need to call RendererBase.Present
after drawing needed objects to a texture, and should not be done; you are only required to change back the rendering target to default via RendererBase.SetTarget(renderer, nullptr)
afterwards, as textures by themselves do not have a concept of backbuffers. Calling RendererBase.Present while rendering to a texture will still update the screen with any current drawing that has been done to the window itself.
Error | on failure. |
|
inline |
The returned surface contains pixels inside the desired area clipped to the current viewport, and should be freed with SurfaceRef.reset().
Note that this returns the actual pixels on the screen, so if you are using logical presentation you should use RendererBase.GetLogicalPresentationRect() to get the area containing your content.
WARNING: This is a very slow operation, and should not be used frequently. If you're using this on the main rendering target, it should be called after rendering and before RendererBase.Present().
rect | an Rect structure representing the area to read, which will be clipped to the current viewport, or nullptr for the entire viewport. |
Error | on failure. |
|
inline |
This function clears the entire rendering target, ignoring the viewport and the clip rectangle. Note, that clearing will also set/fill all pixels of the rendering target to current renderer draw color, so make sure to invoke RendererBase.SetDrawColor() when needed.
Error | on failure. |
|
inline |
This takes into account several states:
window_coord | the x, y coordinate in window coordinates. |
Error | on failure. |
|
inline |
This takes into account several states:
coord | the x, y coordinate in render coordinates. |
Error | on failure. |
|
inline |
This function will render a string of text to an RendererBase. Note that this is a convenience function for debugging, with severe limitations, and not intended to be used for production apps and games.
Among these limitations:
For serious text rendering, there are several good options, such as SDL_ttf, stb_truetype, or other external libraries.
On first use, this will create an internal texture for rendering glyphs. This texture will live until the renderer is destroyed.
The text is drawn in the color specified by RendererBase.SetDrawColor().
p | the x, y coordinates where the top-left corner of the text will draw. |
str | the string to render. |
Error | on failure. |
|
inline |
This function will render a std::format()-style format string to a renderer. Note that this is a convenience function for debugging, with severe limitations, and is not intended to be used for production apps and games.
For the full list of limitations and other useful information, see SDL_RenderDebugText.
p | the x, y coordinates where the top-left corner of the text will draw. |
fmt | the format string to draw. |
args | additional parameters matching {} tokens in the fmt string, if any. |
Error | on failure. |
|
inline |
rect | a pointer to the destination rectangle, or std::nullopt for the entire rendering target. |
Error | on failure. |
|
inline |
rects | a pointer to an array of destination rectangles. |
Error | on failure. |
|
inline |
p1 | the x,y coordinate of the start point. |
p2 | the x,y coordinate of the end point. |
Error | on failure. |
|
inline |
points | the points along the lines. |
Error | on failure. |
|
inline |
p | the x, y coordinates of the point. |
Error | on failure. |
|
inline |
points | the points to draw. |
Error | on failure. |
|
inline |
rect | a pointer to the destination rectangle, or std::nullopt to outline the entire rendering target. |
Error | on failure. |
|
inline |
rects | a pointer to an array of destination rectangles. |
Error | on failure. |
|
inline |
This is equivalent to SetClipRect(std::nullopt)
Error | on failure. |
|
inline |
This is equivalent to SetViewport(std::nullopt)
Error | on failure. |
|
inline |
Each render target has its own clip rectangle. This function sets the cliprect for the current render target.
rect | an Rect structure representing the clip area, relative to the viewport, or nullptr to disable clipping. |
Error | on failure. |
|
inline |
The color scale is an additional scale multiplied into the pixel color value while rendering. This can be used to adjust the brightness of colors during HDR rendering, or changing HDR video brightness when playing on an SDR display.
The color scale does not affect the alpha channel, only the color brightness.
scale | the color scale value. |
Error | on failure. |
|
inline |
If the blend mode is not supported, the closest supported mode is chosen.
blendMode | the BlendMode to use for blending. |
Error | on failure. |
|
inline |
Set the color for drawing or filling rectangles, lines, and points, and for RendererBase.RenderClear().
c | the color value used to draw on the rendering target. |
Error | on failure. |
|
inline |
Set the color for drawing or filling rectangles, lines, and points, and for RendererBase.RenderClear().
c | the RGBA values used to draw on the rendering target. |
Error | on failure. |
|
inline |
This function sets the width and height of the logical rendering output. The renderer will act as if the current render target is always the requested dimensions, scaling to the actual resolution as necessary.
This can be useful for games that expect a fixed size, but would like to scale the output to whatever is available, regardless of how a user resizes a window, or if the display is high DPI.
Logical presentation can be used with both render target textures and the renderer's window; the state is unique to each render target, and this function sets the state for the current render target. It might be useful to draw to a texture that matches the window dimensions with logical presentation enabled, and then draw that texture across the entire window with logical presentation disabled. Be careful not to render both with logical presentation enabled, however, as this could produce double-letterboxing, etc.
You can disable logical coordinates by setting the mode to LOGICAL_PRESENTATION_DISABLED, and in that case you get the full pixel resolution of the render target; it is safe to toggle logical presentation during the rendering of a frame: perhaps most of the rendering is done to specific dimensions but to make fonts look sharp, the app turns off logical presentation while drawing text, for example.
For the renderer's window, letterboxing is drawn into the framebuffer if logical presentation is enabled during RendererBase.Present; be sure to reenable it before presenting if you were toggling it, otherwise the letterbox areas might have artifacts from previous frames (or artifacts from external overlays, etc). Letterboxing is never drawn into texture render targets; be sure to call RendererBase.RenderClear() before drawing into the texture so the letterboxing areas are cleared, if appropriate.
You can convert coordinates in an event into rendering coordinates using RendererBase.ConvertEventToRenderCoordinates().
size | the width and height of the logical resolution. |
mode | the presentation mode used. |
Error | on failure. |
|
inline |
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.
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.
Each render target has its own scale. This function sets the scale for the current render target.
scale | the x, y scaling factors. |
Error | on failure. |
|
inline |
Drawing will clip to this area (separately from any clipping done with RendererBase.SetClipRect), and the top left of the area will become coordinate (0, 0) for future drawing commands.
The area's width and height must be >= 0.
Each render target has its own viewport. This function sets the viewport for the current render target.
rect | the Rect structure representing the drawing area, or nullptr to set the viewport to the entire target. |
Error | on failure. |
|
inline |
When a renderer is created, vsync defaults to SDL_RENDERER_VSYNC_DISABLED.
The vsync
parameter can be 1 to synchronize present with every vertical refresh, 2 to synchronize present with every second vertical refresh, etc., SDL_RENDERER_VSYNC_ADAPTIVE for late swap tearing (adaptive vsync), or SDL_RENDERER_VSYNC_DISABLED to disable. Not every value is supported by every driver, so you should check the return value to see whether the requested setting is supported.
vsync | the vertical refresh sync interval. |
Error | on failure. |