Skip to content

Text Rendering

Text rendering methods allow you to draw text using system fonts directly onto displays. DirectGPU supports custom font names, sizes, styles, text measurement, and wrapped text rendering.

Method
clearFontCache() : ()
drawText(displayId : DisplayID, text : string, x : number, y : number, r : number, g : number, b : number, fontName : string, fontSize : number, style : string) : table
drawTextWithBg(displayId : DisplayID, text : string, x : number, y : number, fgR : number, fgG : number, fgB : number, bgR : number, bgG : number, bgB : number, padding : number, fontName : string, fontSize : number, style : string) : table
drawTextWrapped(displayId : DisplayID, text : string, x : number, y : number, maxWidth : number, r : number, g : number, b : number, lineSpacing : number, fontName : string, fontSize : number, style : string) : table
measureText(text : string, fontName : string, fontSize : number, style : string) : table
getAvailableFonts() : table

Clears all cached font renderers.

Useful when changing fonts or styles frequently and you want to reset cached font state.

gpu.clearFontCache()

Draws text on a display using a system font.

Available styles depend on the installed font. Common styles include:

  • "plain"
  • "bold"
  • "italic"

Requires: DisplayID, text : string, x : number, y : number, r : number, g : number, b : number, fontName : string, fontSize : number, style : string

Returns: table containing text rendering information.

local info = gpu.drawText(
displayId,
"Hello",
10,
20,
255,
255,
255,
"Arial",
18,
"bold"
)
print(info.width, info.height)

Draws text with a colored background box.

The padding value controls the space between the text and the background edges.

Requires: DisplayID, text parameters, foreground color, background color, padding, font settings.

Returns: table containing text rendering information.

local info = gpu.drawTextWithBg(
displayId,
"Button",
20,
20,
255,
255,
255,
40,
40,
40,
4,
"Arial",
16,
"bold"
)

Draws text while automatically wrapping lines to fit within maxWidth.

Returns:

{
width,
height,
lines
}

Where:

  • width - final rendered width
  • height - final rendered height
  • lines - number of lines drawn

Requires: DisplayID, text, position, maximum width, color, line spacing, font settings.

local info = gpu.drawTextWrapped(
displayId,
"This is a long sentence that will wrap.",
10,
10,
200,
255,
255,
255,
2,
"Arial",
16,
"plain"
)
print(info.lines)

Measures text dimensions without drawing.

Useful for UI layout calculations.

Returns:

{
width,
height
}
local size = gpu.measureText(
"Hello",
"Arial",
18,
"bold"
)
print(size.width, size.height)

Returns a table containing all available system font family names.

local fonts = gpu.getAvailableFonts()
for _, font in pairs(fonts) do
print(font)
end