Skip to content

Per-Viewport HUD

App: apps/split_hud_demo/

A 4-player grid split with a retained-UI HUD that is rendered once (full-window) but replayed into each cell by Graphics.perViewportOverlays(true) (Camera v2, CAM-18 / ADR 0064) — so every player gets the HUD in their own region, scissored so it never spills across a divider.

import "engine" for Graphics, Window, SplitScreen, SplitLayout, Ui
var split = SplitScreen.new(scene, players)
split.layout(SplitLayout.grid)
var hud = Ui.load("ui/main.ui")
Graphics.perViewportOverlays(true) // replay the HUD per split-screen cell
// in draw(): render the HUD once, full-window — the renderer replays it per cell.
Ui.render(hud, 0, 0, Window.getWidth(), Window.getHeight())
Terminal window
% ./plume3d split_hud_demo

Each of the four cells shows the same HUD in its own region: a green “health bar” pinned to the cell’s top-left and a magenta marker pinned to the cell’s bottom-right — clipped to the cell (no spill across the dividers).

Graphics.perViewportOverlays(on) sets a flag; when set and the frame has split-screen viewports, the renderer builds the retained-UI overlay batches once, then replays them into each viewport’s sub-rect — a sub-rect VkViewport scales the full-window HUD into the cell, and a matching scissor clips it so it stays inside the cell.

Scope: screen-space retained UI only (the per-player HUD). World-space overlays (billboard sprites, world-space SDF text) are scene content, and screen-space SDF text per viewport is a follow-up.