Tryst::SDL::Renderer
The drawing API over a Viewport's SDL renderer.
viewport.render do |r|
r.clear(Tryst::SDL::Color::BLACK)
r.fill_rect(10, 10, 100, 50, color: Tryst::SDL::Color.new(255, 0, 0))
end
Every call raises on failure rather than returning a boolean. SDL3 reports errors that way and a drawing call that quietly did nothing is close to impossible to find later, because the symptom is a blank area rather than an error.
Constructors
Instance methods
Fills the whole target. With no colour, uses the current one.
Draws a texture. With no rects, the whole texture over the whole
target; src takes part of the texture, dest places it.
A new texture belonging to this renderer. See Texture for which access to pick; the caller owns it and should #destroy it.
Draws an arbitrary list of coloured (and, with a texture, textured) triangles - the one primitive #fill_rect/#draw_line/ #copy don't cover, since all of them are axis-aligned or whole- texture. Gradients, polygons, particle fans, custom meshes.
With no indices, every three vertices in order become one triangle - SDL's own default. With indices, each group of three indexes into vertices instead, so a shared vertex (a fan's centre, an edge shared between two triangles) is written once and reused rather than duplicated.
A CONNECTED polyline through the points, not a set of separate segments - the same distinction SDL draws between RenderLines and repeated RenderLine.
An Array/Slice(Point) is handed to SDL directly with no per-call copy - see #point_ptr. Anything else (a general Enumerable, a lazily generated sequence) still works via the fallback below, which builds the array SDL needs.
See #draw_lines for the Array/Slice(Point) vs. Enumerable(Point) split.
Renders text and draws it at (x, y) in one call.
This creates a texture and destroys it again every call - fine for text that changes every frame (a score, a clock), wasteful for anything static. Render once through Font#render_text and reuse the texture instead when the text does not change.
Draws into a texture instead of the window, for the duration of the block.
The previous target is restored afterwards even if the block raises - forgetting to put it back leaves every later draw going somewhere invisible, which presents as the whole program having stopped rendering.
A TrueType/OpenType font at the given point size, for text drawn with #draw_text or rendered directly through Font#render_text.
An image file loaded straight into a GPU texture - PNG, JPG, BMP, GIF, WebP, TGA and whatever else this build's SDL3_image supports. Alpha blending is on by default, since a loaded image with transparency (a PNG sprite) is the common case and a surprising blank rect is the alternative.
Puts everything drawn since the last present on screen.
Nothing appears without this, which is the single most common
reason a renderer looks like it is doing nothing at all -
Viewport#render exists so it cannot be forgotten.
Reads the drawn pixels back, yielding them and freeing the snapshot afterwards. Yielded rather than returned so the surface cannot outlive its own cleanup.
Slow - it stalls the pipeline waiting for the GPU - so this is for tests and screenshots.