renderer
pykraken.renderer Functions for rendering graphics
At a glance
15 membersclearfunctiondrawfunctiondraw_9slicefunctiondraw_batchfunctionget_current_resolutionfunctionget_default_filter_modefunctionget_output_resolutionfunctionget_virtual_resolutionfunctionpresentfunctionread_pixelsfunctionset_default_filter_modefunctionset_render_backendfunctionset_targetfunctionset_virtual_resolutionfunctionunset_virtual_resolutionfunctionReference
PYTHON APIclear
functionClear the renderer with the specified color.
Args
- color (
Color, optional) — The color to clear with. Defaults to black (0, 0, 0, 255).
Raises
- ValueError — If color values are not between 0 and 255.
draw(texture: Texture, transform: Transform = <Transform object>, anchor: Vec2 = Vec2(0.000000, 0.000000), pivot: Vec2 = Vec2(0.500000, 0.500000), *, options: DrawOptions | None = None, source: Rect | None = None, tint: Color | None = None, alpha: float | None = None, flip_h: bool | None = None, flip_v: bool | None = None, blend: BlendMode | None = None) -> Nonedraw(texture: Texture, dst: Rect, angle: float = 0.0, pivot: Vec2 = Vec2(0.500000, 0.500000), *, options: DrawOptions | None = None, source: Rect | None = None, tint: Color | None = None, alpha: float | None = None, flip_h: bool | None = None, flip_v: bool | None = None, blend: BlendMode | None = None) -> NoneOverloaded function.
draw(texture: Texture, transform: Transform = <Transform object>, anchor: Vec2 = Vec2(0.000000, 0.000000), pivot: Vec2 = Vec2(0.500000, 0.500000), *, options: DrawOptions | None = None, source: Rect | None = None, tint: Color | None = None, alpha: float | None = None, flip_h: bool | None = None, flip_v: bool | None = None, blend: BlendMode | None = None) -> None
Draw a texture in world coordinates. Properties are local to this call.
Args
- texture (
Texture) — The texture to draw. - transform (
Transform, optional) — The position, rotation, and scale of the texture. Defaults to no transform. - anchor (
Vec2, optional) — The anchor point of the texture. Defaults to Anchor.TOP_LEFT. - pivot (
Vec2, optional) — The pivot point for rotation and scaling. Defaults to Anchor.CENTER. - options (
DrawOptions, optional) — Additional draw options. Defaults to None. - source (
Rect, optional) — The source rectangle from the texture. Defaults to None (full texture). - tint (
Color, optional) — The color tint to apply. Defaults to None (no tint). - alpha (
float, optional) — The alpha multiplier (0..1). Defaults to None (no change). - flip_h (
bool, optional) — Whether to flip the texture horizontally. Defaults to None (no flip). - flip_v (
bool, optional) — Whether to flip the texture vertically. Defaults to None (no flip). - blend (
BlendMode, optional) — The blend mode to use. Defaults to None (normal blending).
draw(texture: Texture, dst: Rect, angle: float = 0.0, pivot: Vec2 = Vec2(0.500000, 0.500000), *, options: DrawOptions | None = None, source: Rect | None = None, tint: Color | None = None, alpha: float | None = None, flip_h: bool | None = None, flip_v: bool | None = None, blend: BlendMode | None = None) -> None
Draw a texture into a screen-space rectangle, bypassing the camera.
Args
- texture (
Texture) — The texture to draw. - dst (
Rect) — The destination rectangle in screen coordinates. - angle (
float, optional) — The rotation angle in degrees. Defaults to 0. - pivot (
Vec2, optional) — The pivot point for rotation and scaling. Defaults to Anchor.CENTER. - options (
DrawOptions, optional) — Additional draw options. Defaults to None. - source (
Rect, optional) — The source rectangle from the texture. Defaults to None (full texture). - tint (
Color, optional) — The color tint to apply. Defaults to None (no tint). - alpha (
float, optional) — The alpha multiplier (0..1). Defaults to None (no change). - flip_h (
bool, optional) — Whether to flip the texture horizontally. Defaults to None (no flip). - flip_v (
bool, optional) — Whether to flip the texture vertically. Defaults to None (no flip). - blend (
BlendMode, optional) — The blend mode to use. Defaults to None (normal blending).
draw_9slice
functionDraw a nine-slice in screen coordinates.
Args
- texture (
Texture) — The texture to draw. - dst (
Rect) — The destination rectangle in screen coordinates. - slice (
Rect) — The nine-slice rectangle in texture coordinates. - options (
DrawOptions, optional) — Additional draw options. Defaults to None. - source (
Rect, optional) — The source rectangle from the texture. Defaults to None (full texture). - tint (
Color, optional) — The color tint to apply. Defaults to None (no tint). - alpha (
float, optional) — The alpha multiplier (0..1). Defaults to None (no change). - flip_h (
bool, optional) — Whether to flip the texture horizontally. Defaults to None (no flip). - flip_v (
bool, optional) — Whether to flip the texture vertically. Defaults to None (no flip). - blend (
BlendMode, optional) — The blend mode to use. Defaults to None (normal blending).
draw_batch(texture: Texture, transforms: ndarray[dtype=float64, shape=(*, *), order='C', device='cpu', writable=False], anchor: Vec2 = Vec2(0.000000, 0.000000), pivot: Vec2 = Vec2(0.500000, 0.500000), batcher: renderer.Batcher | None = None, *, options: DrawOptions | None = None, source: Rect | None = None, tint: Color | None = None, alpha: float | None = None, flip_h: bool | None = None, flip_v: bool | None = None, blend: BlendMode | None = None, instance_options: Sequence[DrawOptions] | None = None, clip_rects: Sequence[Rect] | None = None) -> Nonedraw_batch(texture: Texture, transforms: Sequence[Transform], anchor: Vec2 = Vec2(0.000000, 0.000000), pivot: Vec2 = Vec2(0.500000, 0.500000), clip_rects: Sequence[Rect] | None = None, *, options: DrawOptions | None = None, source: Rect | None = None, tint: Color | None = None, alpha: float | None = None, flip_h: bool | None = None, flip_v: bool | None = None, blend: BlendMode | None = None, instance_options: Sequence[DrawOptions] | None = None) -> NoneOverloaded function.
draw_batch(texture: Texture, transforms: ndarray[dtype=float64, shape=(*, *), order='C', device='cpu', writable=False], anchor: Vec2 = Vec2(0.000000, 0.000000), pivot: Vec2 = Vec2(0.500000, 0.500000), batcher: renderer.Batcher | None = None, *, options: DrawOptions | None = None, source: Rect | None = None, tint: Color | None = None, alpha: float | None = None, flip_h: bool | None = None, flip_v: bool | None = None, blend: BlendMode | None = None, instance_options: Sequence[DrawOptions] | None = None, clip_rects: Sequence[Rect] | None = None) -> None
Draw a contiguous float64 NumPy array with 2, 3, 4, 5, or 9 columns: [x, y, (angle), (scale or scale_x, scale_y), (source_x, source_y, source_w, source_h)]. The shared-style path uses geometry and optionally reusable Batcher buffers. Per-instance colors, flips, and sources remain on the geometry path. Blend-mode changes split geometry submissions while preserving order. Array source columns override option sources; clip_rects overrides both.
Args
- texture (
Texture) — The texture to draw. - transforms (
ndarray) — A 2D NumPy array of shape (N, M) where N is the number of instances and M is 2, 3, 4, 5, or 9. - anchor (
Vec2, optional) — The anchor point of the texture. Defaults to Anchor.TOP_LEFT. - pivot (
Vec2, optional) — The pivot point for rotation and scaling. Defaults to Anchor.CENTER. - batcher (
Batcher, optional) — A reusable Batcher for internal memory. Defaults to None (internal allocation). - options (
DrawOptions, optional) — Additional draw options. Defaults to None. - source (
Rect, optional) — The source rectangle from the texture. Defaults to None (full texture). - tint (
Color, optional) — The color tint to apply. Defaults to None (no tint). - alpha (
float, optional) — The alpha multiplier (0..1). Defaults to None (no change). - flip_h (
bool, optional) — Whether to flip the texture horizontally. Defaults to None (no flip). - flip_v (
bool, optional) — Whether to flip the texture vertically. Defaults to None (no flip). - blend (
BlendMode, optional) — The blend mode to use. Defaults to None (normal blending). - instance_options (
list of DrawOptions, optional) — A list of DrawOptions for each instance. Must have the same length as transforms if provided. - clip_rects (
list of Rect, optional) — A list of source rectangles for each instance. Must have the same length as transforms if provided.
draw_batch(texture: Texture, transforms: Sequence[Transform], anchor: Vec2 = Vec2(0.000000, 0.000000), pivot: Vec2 = Vec2(0.500000, 0.500000), clip_rects: Sequence[Rect] | None = None, *, options: DrawOptions | None = None, source: Rect | None = None, tint: Color | None = None, alpha: float | None = None, flip_h: bool | None = None, flip_v: bool | None = None, blend: BlendMode | None = None, instance_options: Sequence[DrawOptions] | None = None) -> None
Draw a sequence of transforms using local properties. instance_options, if supplied, replaces common options per instance and must have one entry per transform. clip_rects overrides source and must match the batch length.
Args
- texture (
Texture) — The texture to draw. - transforms (
list of Transform) — A list of Transform objects for each instance. - anchor (
Vec2, optional) — The anchor point of the texture. Defaults to Anchor.TOP_LEFT. - pivot (
Vec2, optional) — The pivot point for rotation and scaling. Defaults to Anchor.CENTER. - clip_rects (
list of Rect, optional) — A list of source rectangles for each instance. Must have the same length as transforms if provided. - options (
DrawOptions, optional) — Additional draw options. Defaults to None. - source (
Rect, optional) — The source rectangle from the texture. Defaults to None (full texture). - tint (
Color, optional) — The color tint to apply. Defaults to None (no tint). - alpha (
float, optional) — The alpha multiplier (0..1). Defaults to None (no change). - flip_h (
bool, optional) — Whether to flip the texture horizontally. Defaults to None (no flip). - flip_v (
bool, optional) — Whether to flip the texture vertically. Defaults to None (no flip). - blend (
BlendMode, optional) — The blend mode to use. Defaults to None (normal blending).
get_current_resolution
functionget_current_resolution() -> Vec2Get the resolution of the current render target for rendering. If a custom render target is set, this will return the size of it. Otherwise, it returns the presenting resolution of the renderer.
Returns
- Vec2 — The width and height of the current resolution.
get_default_filter_mode
functionget_default_filter_mode() -> FilterModeGet the current default FilterMode for new textures.
Returns
- FilterMode — The current default scaling/filtering mode.
get_output_resolution
functionget_output_resolution() -> Vec2Get the renderer's output/presenting resolution (the actual window or output size).
Returns
- Vec2 — The output width and height in pixels.
get_virtual_resolution
functionget_virtual_resolution() -> Vec2Get the currently configured virtual resolution (the internal render target size). If no virtual resolution is set, this returns the current output resolution.
Returns
- Vec2 — The width and height of the virtual resolution in pixels.
present
functionpresent() -> NonePresent the rendered content to the screen. This finalizes the current frame and displays it. Should be called after all drawing operations for the frame are complete.
read_pixels
functionread_pixels(src: Rect = Rect(x=0.000000, y=0.000000, w=0.000000, h=0.000000)) -> PixelArrayRead pixel data from the renderer within the specified rectangle.
Args
- src (
Rect, optional) — The rectangle area to read pixels from. Defaults to entire renderer if None or area has no width or height.
Returns
- PixelArray — An array containing the pixel data.
Raises
- RuntimeError — If reading pixels fails.
set_default_filter_mode
functionset_default_filter_mode(filter: FilterMode) -> NoneSet the default FilterMode for new textures. The factory default is FilterMode::Default.
Args
- filter (
FilterMode) — The default scaling/filtering mode to use for new textures.
set_render_backend
functionset_render_backend(backend: RenderBackend) -> NoneSet the renderer backend to use for future initialization. This must be called before creating the window/renderer, otherwise it will have no effect.
Args
- backend (
RenderBackend) — One of the RenderBackend enum values.
set_target
functionset_target(target: Texture | None = None) -> NoneSet the current render target to the provided Texture.
Args
- target (
Texture, optional) — A Texture created with TextureAccess.TARGET, or None to unset.
Raises
- RuntimeError — If the texture is not a TARGET texture.
set_virtual_resolution
functionset_virtual_resolution(width: int, height: int) -> NoneSet a virtual resolution for rendering. This creates an internal render target of the specified size, and all rendering will be done to that target, which is then scaled up to the actual screen resolution when presented.
Args
- width (
int) — The width of the render target in pixels. - height (
int) — The height of the render target in pixels.
Raises
- ValueError — If width or height are not positive integers.
unset_virtual_resolution
functionunset_virtual_resolution() -> NoneUnset any previously configured virtual resolution and restore rendering directly to the output.