Off-screen Regions and High-DPI Displays

Rendering to a texture

RmlRegion.make() accepts any GraphicsOutput, so an interface can be rendered into a texture buffer and shown on a model: a terminal on a monitor, a control panel on a machine. The samples/rocket-console sample does exactly this.

buffer = base.win.makeTextureBuffer("console", 1024, 512)
texture = buffer.getTexture()
screen_model.setTexture(texture, 1)

region = RmlRegion.make("console", buffer)
region.set_input_handler(handler)
context = region.get_context()
context.load_font_face("fonts/dos437.ttf")
context.load_document("ui/console.rml").show()

The buffer renders before the window, so the texture is current when the model draws. The context’s size is the buffer’s size.

The texture holds the page’s colours as display (sRGB) values. A scene that lights linear colour should decode them when it samples the panel: give the buffer an sRGB colour buffer, so that its texture is an sRGB texture.

fbp = FrameBufferProperties()
fbp.set_rgba_bits(8, 8, 8, 8)
fbp.set_stencil_bits(8)
fbp.set_srgb_color(True)
buffer = base.win.makeTextureBuffer("console", 1024, 512, fbp=fbp)

The region still writes the bytes as authored (an RmlRegion is never encoded; see DisplayRegion.framebuffer_srgb); the model’s shader reads them back as the linear colours they stand for.

High-DPI displays

RmlUi lays out in density-independent pixels, dp, scaled by the context’s density-independent pixel ratio. When a window opens on a high-DPI display with dpi-aware enabled, the framebuffer has more pixels than the logical size that was requested; the region detects this and sets the ratio so that dp sizes – fonts, layout – keep their intended physical size while text is rasterised at native resolution. Override it with RmlContext.set_density_independent_pixel_ratio() to scale an interface up or down deliberately.

Media queries work with the same scale: @media (max-width: 800dp) is evaluated in dp, ratio included, so a breakpoint written once behaves the same on every display. Element geometry returned by RmlElement, on the other hand, is always in framebuffer pixels.