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.
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.