Hi I am new to Fabric and I am trying to render text on top of a rect I rendered. See the below code for an example.
HudRenderCallback.EVENT.register { drawCtx, _ ->
val client = MinecraftClient.getInstance()
val width = client.window.scaledWidth
val matrices = drawCtx.matrices
val marginsTopRight = 10f
// Both excluding our margins as these are applied when .translate is called.
val widgetWidth = 200
val widgetHeight = 50
matrices.push()
// We can use the MatrixStack to add our UI with 10px margin to the top right.
// This sets the rendering origin so we can focus on drawing using local coordinates.
matrices.translate(
width.toFloat() - marginsTopRight - widgetWidth,
marginsTopRight, 0f
)
drawCtx.fill(0, 0, widgetWidth, widgetHeight, 1, 0xFF444444.toInt())
val textRenderer = client.textRenderer
drawCtx.drawText(
textRenderer, "Hello, world!", 0,
0, 0xFFFFFFFF.toInt(), true
)
matrices.pop()
}
Rendering text after calling pop() does work but ruins the point of having a relative coordinate system.
Thanks in advance!