simvx.graphics.draw2d

Immediate-mode 2D drawing API for Vulkan backend.

Matches the SDL3 Renderer2D interface so 2D games work on both backends. Collects per-frame geometry into CPU buffers; Draw2DPass uploads and renders.

Module Contents

Classes

Draw2D

Vulkan-backed 2D drawing API matching SDL3 Renderer2D interface.

Data

API

simvx.graphics.draw2d.__all__

[‘Draw2D’, ‘UI_VERTEX_DTYPE’]

class simvx.graphics.draw2d.Draw2D[source]

Bases: simvx.graphics.draw2d_transform.Draw2DTransformMixin, simvx.graphics.draw2d_text.Draw2DTextMixin, simvx.graphics.draw2d_texture.Draw2DTextureMixin, simvx.graphics.draw2d_batch.Draw2DBatchMixin

Vulkan-backed 2D drawing API matching SDL3 Renderer2D interface.

classmethod set_colour(r=255, g=255, b=255, a=255)[source]

Set the active draw colour. Accepts 0-255 ints or 0.0-1.0 floats.

classmethod fill_rect(pos, size_or_y=None, w=None, h=None)[source]
classmethod draw_rect(pos, size_or_y=None, w=None, h=None, colour=None)[source]

Draw a rect outline. Accepts:

  • draw_rect(Vec2_pos, Vec2_size)

  • draw_rect(x, y, w, h)

  • draw_rect(x, y, w, h, colour)

classmethod draw_line(a, b_or_y=None, x2=None, y2=None)[source]

Draw a line. Accepts:

  • draw_line(Vec2_a, Vec2_b)

  • draw_line((x1,y1), (x2,y2))

  • draw_line((x1,y1), (x2,y2), colour)

  • draw_line((x1,y1), (x2,y2), colour, width)

  • draw_line(x1, y1, x2, y2)

classmethod draw_lines(points, closed=True, colour=None)[source]
classmethod draw_circle(center, radius_or_y=None, radius=None, segments=24, colour=None)[source]
classmethod fill_triangle(x1, y1, x2, y2, x3, y3)[source]

Emit a single filled triangle.

classmethod draw_polygon(vertices, colour=None)[source]

Fill a convex polygon using triangle fan from first vertex.

Args: vertices: List of (x, y) tuples or Vec2 objects. colour: Optional RGBA float tuple to set before drawing.

classmethod fill_quad(x1, y1, x2, y2, x3, y3, x4, y4)[source]

Emit a filled quad from four arbitrary corners (two triangles).

classmethod draw_thick_line(x1, y1, x2, y2, width=2.0)[source]

Draw a thick line as a filled quad using perpendicular offsets.

classmethod fill_circle(cx, cy, radius, segments=24)[source]

Emit a filled circle as a triangle fan (indexed triangles).

classmethod draw_thick_line_coloured(x1, y1, x2, y2, width, colour)[source]

Set colour (float 0-1 tuple) and draw_thick_line in one call.

classmethod draw_filled_circle(cx, cy, radius, colour, segments=24)[source]

Set colour and fill_circle in one call.

classmethod draw_filled_triangle(x1, y1, x2, y2, x3, y3, colour)[source]

Set colour and fill_triangle in one call.

classmethod draw_filled_quad(x1, y1, x2, y2, x3, y3, x4, y4, colour)[source]

Set colour and fill_quad in one call.

classmethod fill_rect_gradient(x, y, w, h, colour_top, colour_bottom)[source]

Fill rect with vertical gradient (top colour -> bottom colour).

classmethod draw_gradient_rect(x, y, w, h, colour_top, colour_bottom)[source]

Convenience: fill_rect_gradient with float-tuple colours.

classmethod draw_filled_rect(x, y, w, h, colour)[source]

Set colour (float 0-1 tuple) and fill_rect in one call.

classmethod draw_rect_coloured(x, y, w, h, colour)[source]

Set colour (float 0-1 tuple) and draw_rect in one call.

classmethod draw_line_coloured(x1, y1, x2, y2, colour)[source]

Set colour (float 0-1 tuple) and draw_line in one call.

classmethod clear(r=0, g=0, b=0)[source]
classmethod present()[source]
classmethod push_transform(a, b, c, d, tx, ty)
classmethod pop_transform()
classmethod push_identity()
classmethod set_font(path: str | None = None, size: int = 48) None
classmethod draw_text(text, pos, scale=1, colour=None)
classmethod text_width(text, scale=1)
classmethod draw_text_coloured(text, x, y, scale=1, colour=None)
classmethod register_texture(png_data: bytes) int
classmethod register_texture_with_id(texture_id: int, png_data: bytes) None
classmethod draw_texture(texture_id: int, x: float, y: float, w: float, h: float, colour: tuple[float, ...] | None = None, rotation: float = 0.0)
classmethod draw_texture_region(texture_id: int, x: float, y: float, w: float, h: float, u0: float = 0.0, v0: float = 0.0, u1: float = 1.0, v1: float = 1.0, colour: tuple[float, ...] | None = None, rotation: float = 0.0)
classmethod draw_nine_patch(texture_id: int, x: float, y: float, w: float, h: float, tex_w: float, tex_h: float, margin_left: float = 0.0, margin_right: float = 0.0, margin_top: float = 0.0, margin_bottom: float = 0.0, draw_centre: bool = True, colour: tuple[float, ...] | None = None)
classmethod push_clip(x: int, y: int, w: int, h: int)
classmethod pop_clip()
classmethod new_layer()
classmethod reset_clip()