Skip to main content

Overview

Text functions provide capabilities for rendering text, loading custom fonts, and measuring text dimensions.

Basic Text Drawing

drawText

Draws text using the default font.
text
String
required
Text to draw
posX
Number
required
X position
posY
Number
required
Y position
fontSize
Number
required
Font size
color
Color
required
Text color
import "raylib" for Raylib, Color

Raylib.initWindow(800, 450, "Text Example")
Raylib.setTargetFPS(60)

var title = "Hello Talon!"
var color = Color.Purple

while (!Raylib.windowShouldClose()) {
  Raylib.beginDrawing()
  Raylib.clearBackground(Color.RayWhite)
  
  Raylib.drawText(title, 20, 20, 60, color)
  Raylib.drawText("FPS: %(Raylib.getFPS())", 10, 100, 20, Color.Green)
  
  Raylib.endDrawing()
}

Raylib.closeWindow()

drawFPS

Draws current FPS at specified position.
posX
Number
required
X position
posY
Number
required
Y position
Raylib.drawFPS(10, 10)

Custom Font Drawing

drawTextEx

Draws text using a custom font with spacing.
font
Font
required
Font to use
text
String
required
Text to draw
position
Vector2
required
Position to draw at
fontSize
Number
required
Font size
spacing
Number
required
Character spacing
tint
Color
required
Text color
var font = Raylib.loadFont("resources/font.ttf")
var position = Vector2.new(100, 100)
var fontSize = 32
var spacing = 2

Raylib.drawTextEx(font, "Custom Font Text", position, fontSize, spacing, Color.Black)

Raylib.unloadFont(font)

drawTextPro

Draws text using font with pro parameters (rotation, origin).
font
Font
required
Font to use
text
String
required
Text to draw
position
Vector2
required
Position
origin
Vector2
required
Rotation origin
rotation
Number
required
Rotation in degrees
fontSize
Number
required
Font size
spacing
Number
required
Character spacing
tint
Color
required
Text color
var rotation = 45.0
var origin = Vector2.new(0, 0)
Raylib.drawTextPro(font, "Rotated Text", Vector2.new(400, 300), origin, rotation, 32, 2, Color.Red)

Font Loading

loadFont

Loads font from file into GPU memory (TTF, OTF).
fileName
String
required
Path to font file
Returns: Font - Loaded font
var customFont = Raylib.loadFont("resources/pixelfont.ttf")

// Use the font
Raylib.drawTextEx(customFont, "Pixel Text", Vector2.new(10, 10), 20, 1, Color.Black)

// Don't forget to unload
Raylib.unloadFont(customFont)

loadFontEx

Loads font from file with extended parameters.
fileName
String
required
Path to font file
fontSize
Number
required
Base font size
codepoints
Array
required
Array of codepoints to load (null for default)
codepointCount
Number
required
Number of codepoints
Returns: Font - Loaded font

getFontDefault

Returns the default font. Returns: Font - Default font
var defaultFont = Raylib.getFontDefault()

isFontValid

Checks if a font is valid.
font
Font
required
Font to check
Returns: Boolean - True if valid

unloadFont

Unloads font from GPU memory.
font
Font
required
Font to unload
Raylib.unloadFont(customFont)

Text Measurement

measureText

Measures string width for default font.
text
String
required
Text to measure
fontSize
Number
required
Font size
Returns: Number - Text width in pixels
var text = "Hello World"
var fontSize = 20
var textWidth = Raylib.measureText(text, fontSize)

var screenWidth = Raylib.getScreenWidth()
var centerX = (screenWidth - textWidth) / 2

Raylib.drawText(text, centerX, 200, fontSize, Color.Black)

measureTextEx

Measures string size for Font.
font
Font
required
Font to use for measurement
text
String
required
Text to measure
fontSize
Number
required
Font size
spacing
Number
required
Character spacing
Returns: Vector2 - Text dimensions (width, height)
var textSize = Raylib.measureTextEx(customFont, "Test", 32, 2)
var width = textSize.x
var height = textSize.y

Text Configuration

setTextLineSpacing

Sets vertical line spacing when drawing text.
spacing
Number
required
Line spacing in pixels
Raylib.setTextLineSpacing(20)

Text Manipulation

These functions operate on strings at the Wren level:

textLength

Returns text length (including null terminator).
text
String
required
Text to measure
Returns: Number - Text length

textCopy

Copies text to another string.
dst
String
required
Destination string
src
String
required
Source string

textIsEqual

Checks if two text strings are equal.
text1
String
required
First text
text2
String
required
Second text
Returns: Boolean - True if equal

textSubtext

Returns a substring from text.
text
String
required
Source text
position
Number
required
Start position
length
Number
required
Substring length
Returns: String - Substring

textToUpper

Converts string to uppercase.
text
String
required
Text to convert
Returns: String - Uppercase text

textToLower

Converts string to lowercase.
text
String
required
Text to convert
Returns: String - Lowercase text

textToInteger

Converts text to integer.
text
String
required
Text to convert
Returns: Number - Integer value
var scoreText = "1234"
var score = Raylib.textToInteger(scoreText)

textToFloat

Converts text to float.
text
String
required
Text to convert
Returns: Number - Float value

Complete Example

import "raylib" for Raylib, Color, Vector2

var screenWidth = 800
var screenHeight = 450

Raylib.initWindow(screenWidth, screenHeight, "Text Example")
Raylib.setTargetFPS(60)

var customFont = Raylib.loadFont("resources/myfont.ttf")

var title = "Talon Game Engine"
var subtitle = "Powered by Raylib"

while (!Raylib.windowShouldClose()) {
  Raylib.beginDrawing()
  Raylib.clearBackground(Color.RayWhite)
  
  // Center title
  var titleWidth = Raylib.measureText(title, 60)
  var titleX = (screenWidth - titleWidth) / 2
  Raylib.drawText(title, titleX, 100, 60, Color.Purple)
  
  // Draw subtitle with custom font
  var subtitleSize = Raylib.measureTextEx(customFont, subtitle, 30, 2)
  var subtitleX = (screenWidth - subtitleSize.x) / 2
  Raylib.drawTextEx(customFont, subtitle, Vector2.new(subtitleX, 200), 30, 2, Color.DarkGray)
  
  // Show FPS
  Raylib.drawFPS(10, 10)
  
  Raylib.endDrawing()
}

Raylib.unloadFont(customFont)
Raylib.closeWindow()

Best Practices

Load fonts once during initialization for better performance.
Use measureText() or measureTextEx() to center text or calculate layout dimensions.
Always unload custom fonts when done:
Raylib.unloadFont(customFont)

Build docs developers (and LLMs) love