Skip to content

2D Primitives ​

Functions for the 2D batch renderer. All primitives are z-sorted and flushed with vio_draw_2d().

vio_rect ​

php
void vio_rect(VioContext $ctx, float $x, float $y, float $w, float $h, ?array $opts = null)

Draw a filled or outlined rectangle.

Options:

KeyTypeDefaultDescription
color / fillint0xFFFFFFFFAARRGGBB color
outlineboolfalseDraw outline only
zfloat0.0Z-order for sorting

vio_rounded_rect ​

php
void vio_rounded_rect(VioContext $ctx, float $x, float $y, float $w, float $h, float $radius, ?array $opts = null)

Draw a rectangle with rounded corners.

Options: Same as vio_rect.

vio_circle ​

php
void vio_circle(VioContext $ctx, float $cx, float $cy, float $radius, ?array $opts = null)

Draw a filled or outlined circle.

Options:

KeyTypeDefaultDescription
color / fillint0xFFFFFFFFAARRGGBB color
outlineboolfalseDraw outline only
segmentsintautoNumber of circle segments
zfloat0.0Z-order

vio_line ​

php
void vio_line(VioContext $ctx, float $x1, float $y1, float $x2, float $y2, ?array $opts = null)

Draw a line segment.

Options:

KeyTypeDefaultDescription
colorint0xFFFFFFFFAARRGGBB color
zfloat0.0Z-order

WARNING

Line rendering may produce no visible pixels on some GPU/driver configurations.

vio_sprite ​

php
void vio_sprite(VioContext $ctx, VioTexture $texture, ?array $opts = null)

Draw a textured quad.

Options:

KeyTypeDefaultDescription
xfloat0.0X position
yfloat0.0Y position
widthfloattexture widthDisplay width
heightfloattexture heightDisplay height
scale_xfloat1.0Horizontal scale
scale_yfloat1.0Vertical scale
colorint0xFFFFFFFFTint color (white = no tint)
zfloat0.0Z-order

vio_draw_2d ​

php
void vio_draw_2d(VioContext $context)

Flush the 2D batch. Sorts all queued primitives by z-value, batches by texture, and renders in a single pass. Call this before vio_end().

Maximum batch size: 4096 items per frame.

vio_push_transform ​

php
void vio_push_transform(VioContext $ctx, float $a, float $b, float $c, float $d, float $e, float $f)

Push a 2x3 affine transformation matrix onto the transform stack. Affects all subsequent 2D primitives.

Matrix layout:

| a  c  e |
| b  d  f |
| 0  0  1 |

vio_pop_transform ​

php
void vio_pop_transform(VioContext $context)

Pop the top transformation matrix from the stack.

vio_push_scissor ​

php
void vio_push_scissor(VioContext $ctx, float $x, float $y, float $w, float $h)

Push a scissor rectangle. Only pixels within this rect are rendered. Nested scissors are intersected.

vio_pop_scissor ​

php
void vio_pop_scissor(VioContext $context)

Pop the top scissor rectangle.

Color Format ​

Colors are 32-bit unsigned integers in 0xAARRGGBB order:

BitsChannel
24–31Alpha
16–23Red
8–15Green
0–7Blue
php
0xFFFF0000  // Red, opaque
0xFF00FF00  // Green, opaque
0xFF0000FF  // Blue, opaque
0xFFFFFFFF  // White, opaque
0x80FFFFFF  // White, 50% alpha
0x00000000  // Transparent

A literal with alpha 00 draws nothing: 0x00FF00FF is fully transparent magenta, not green.

Released under the MIT License.