Font Rendering - 0x3C50/Renderer GitHub Wiki

The renderer library provides an efficient and easy way to render high-resolution text, directly in minecraft.

Getting the font ready

To do this, you first need to get your Font object loaded, and then pass it into the FontRenderer class.

The font renderer has backup support, which means that you can supply multiple fonts. If the first font doesn't have the requested glyph, the second one is searched. If that one doesn't have it either, the third one is searched, etc. If no font has the glyph, the "missing glyph" symbol is drawn.

Example

Font font = new Font("JetBrains Mono", Font.PLAIN, 18); // size doesn't matter here
FontRenderer renderer = new FontRenderer(new Font[] {font}, 9f);

Drawing

The FontRenderer class provides basic drawing capabilities, including the minecraft color formatting standard using the § sign. To draw text using the font, call .drawString(matrixStack, text, x, y, r, g, b, a). Similarly, .drawCenteredString works the same as .drawString, except that it centers the text on the X axis.

Example

// hud render event
renderer.drawString(matrixStack, "This is red text, §athis is green text, §rthis is back to red", 5, 5, 1, 0, 0, 0);

drawString takes the color to draw the text in as 4 floats, them being red, green, blue, alpha respectively. They're ranged 0-1 and can be found at the end of the method call, in this example.

Destroying

If you want to free all resources taken up by the font renderer, call .destroy() on it. The font renderer can continue to be used, but all glyph maps will have been freed, and need to regenerate (when used).