#Can't see rendered text on screen using HudRenderCallback w/ MatrixStack

12 messages · Page 1 of 1 (latest)

winter lotus
#

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!

#

This is on 1.21.4 btw

earnest slate
#

are you sure the text isn't rendering behind the rect?

winter lotus
#

Probably but I don't know why, or how to fix it

winter lotus
faint halo
#

thats not really how 3 dimensional rendering works

winter lotus
#

So how do I specify the 'z coordinate' for the text, or in other words how can I fix this problem?

south pewter
#

higher Z will be rendered in front of lower Z

winter lotus
#

Do I need to update this for everything layered on top of the rect?

winter lotus
south pewter