Font

Edit

Font objects are used to render text with Pass:text. The active font can be changed using Pass:setFont. The default font is Varela Round, which is used when no font is active, and can be retrieved using lovr.graphics.getDefaultFont. Custom fonts can be loaded from TTF and BMFont files using lovr.graphics.newFont.

Each Font uses a Rasterizer to load the font and create images for each glyph. As text is drawn, the Font uploads images from the Rasterizer to a GPU texture atlas as needed. The Font also performs text layout and mesh generation for strings of text.

For TTF fonts, LÖVR uses a text rendering technique called "multichannel signed distance fields" (MSDF), which makes the font rendering remain crisp when text is viewed up close.

Constructors

lovr.graphics.newFontCreate a new Font.
lovr.graphics.getDefaultFontGet the default Font.

Methods

Font:getAscentGet the ascent of the Font.
Font:getDescentGet the descent of the Font.
Font:getHeightGet the height of the Font.
Font:getKerningGet the kerning between 2 glyphs.
Font:getLineSpacingGet the line spacing of the Font.
Font:getLinesWrap a string into a sequence of lines.
Font:getPixelDensityGet the pixel density of the Font.
Font:getRasterizerGet the Font's Rasterizer.
Font:getVerticesGet the vertices for a piece of text.
Font:getWidthGet the width of rendered text.
Font:setLineSpacingSet the line spacing of the Font.
Font:setPixelDensitySet the pixel density of the Font.

Notes

MSDF text requires a special shader to work. LÖVR will automatically switch to this shader if no shader is active on the Pass. This font shader is also available as a DefaultShader.

See also