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.
Methods
Section titled “Methods”clearFontCache
Section titled “clearFontCache”Clears all cached font renderers.
Useful when changing fonts or styles frequently and you want to reset cached font state.
Example
Section titled “Example”gpu.clearFontCache()drawText
Section titled “drawText”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.
Example
Section titled “Example”local info = gpu.drawText( displayId, "Hello", 10, 20, 255, 255, 255, "Arial", 18, "bold")
print(info.width, info.height)drawTextWithBg
Section titled “drawTextWithBg”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.
Example
Section titled “Example”local info = gpu.drawTextWithBg( displayId, "Button", 20, 20, 255, 255, 255, 40, 40, 40, 4, "Arial", 16, "bold")drawTextWrapped
Section titled “drawTextWrapped”Draws text while automatically wrapping lines to fit within maxWidth.
Returns:
{ width, height, lines}Where:
width- final rendered widthheight- final rendered heightlines- number of lines drawn
Requires: DisplayID, text, position, maximum width, color, line spacing, font settings.
Example
Section titled “Example”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)measureText
Section titled “measureText”Measures text dimensions without drawing.
Useful for UI layout calculations.
Returns:
{ width, height}Example
Section titled “Example”local size = gpu.measureText( "Hello", "Arial", 18, "bold")
print(size.width, size.height)getAvailableFonts
Section titled “getAvailableFonts”Returns a table containing all available system font family names.
Example
Section titled “Example”local fonts = gpu.getAvailableFonts()
for _, font in pairs(fonts) do print(font)end