v2026.11.0
All Bundles
Bundle

SDL2 multimedia library for 2D graphics, input handling, audio playback, and window management. Core types: Window, Renderer, Texture, Surface, Event, and Mixer. Compile with -lib sdl2.

Font

TrueType font rendering

Operations

Free #

Close the font and release it.

TTF_CloseFont was never bound, so until now a loaded font could not be released at all -- which is why every example that draws text simply leaks one.

Font->Quit() is NOT this. That is the static TTF_Quit, which shuts down the whole subsystem; calling it once per font, as some code does, is a different thing entirely.

Safe to call twice -- the handle is cleared. Do not use the font afterwards, and close it before Quit.

method : public : Free() ~ Nil

GetAscent #

Maximum distance of the font's glyphs above the baseline

method : public : GetAscent() ~ Int

Return

TypeDescription
Intascent in pixels, or -1 for a closed font

GetDescent #

Maximum distance of the font's glyphs below the baseline

method : public : GetDescent() ~ Int

Return

TypeDescription
Intdescent in pixels, negative below the baseline; 0 for a closed font

GetHeight #

Maximum height of the font's glyphs

method : public : GetHeight() ~ Int

Return

TypeDescription
Intheight in pixels, or -1 for a closed font

GetLineSkip #

Recommended spacing between lines of text

method : public : GetLineSkip() ~ Int

Return

TypeDescription
Intline skip in pixels, or -1 for a closed font

GetOutline #

Get the outline width

method : public : GetOutline() ~ Int

Return

TypeDescription
Intoutline width in pixels, or -1 for a closed font

GetStyle #

Get the rendering style

method : public : GetStyle() ~ Int

Return

TypeDescription
IntFontStyle values OR'd together, or -1 for a closed font

Init # function

Initialize the TrueType font APIs

function : Init() ~ Int

IsNull #

Determines if the underlying SDL C-struct is NULL

method : public : IsNull() ~ Bool

Return

TypeDescription
Booltrue if NULL, false otherwise

New # constructor

Load file for use as a font, this can load TTF and FON files.

New(file:String, ptsize:Int)

Parameters

NameTypeDescription
fileStringfile name to load font from.
ptsizeIntPoint size (based on 72DPI) to load font as

New # constructor

Load file for use as a font, this can load TTF and FON files.

New(file:String, ptsize:Int, index:Int)

Parameters

NameTypeDescription
fileStringfile name to load font from.
ptsizeIntPoint size (based on 72DPI) to load font as
indexIntchoose a font face from a file containing multiple font faces. The first face is always index 0.

Quit # function

Shutdown and cleanup the TrueType font APIs

function : Quit() ~ Nil

RenderTextBlended #

Render the LATIN1 encoded text blended

method : public : RenderTextBlended(text:String, fg:Color) ~ Surface

Parameters

NameTypeDescription
textStringthe LATIN1 null terminated string to render.
fgColorthe color to render the text in. This becomes colormap index 1.

Return

TypeDescription
SurfaceSurface instance, caller responsible for freeing

RenderTextShaded #

Render the LATIN1 encoded text shaded

method : public : RenderTextShaded(text:String, fg:Color, bg:Color) ~ Surface

Parameters

NameTypeDescription
textStringthe LATIN1 null terminated string to render.
fgColorthe color to render the text in. This becomes colormap index 1.
bgColorthe color to render the background box in. This becomes colormap index 0.

Return

TypeDescription
SurfaceSurface instance, caller responsible for freeing

RenderTextSolid #

Render the LATIN1 encoded text blended

method : public : RenderTextSolid(text:String, fg:Color) ~ Surface

Parameters

NameTypeDescription
textStringthe LATIN1 null terminated string to render.
fgColorthe color to render the text in. This becomes colormap index 1.

Return

TypeDescription
SurfaceSurface instance, caller responsible for freeing

RenderUTF8Blended #

Render the UTF8 encoded text blended

method : public : RenderUTF8Blended(text:String, fg:Color) ~ Surface

Parameters

NameTypeDescription
textStringthe LATIN1 null terminated string to render.
fgColorthe color to render the text in. This becomes colormap index 1.

Return

TypeDescription
SurfaceSurface instance, caller responsible for freeing

RenderUTF8BlendedWrapped #

Render UTF8 text blended, wrapping lines at word boundaries so no line is wider than wrap_length pixels. Lines are also broken at newlines.

method : public : RenderUTF8BlendedWrapped(text:String, fg:Color, wrap_length:Int) ~ Surface

Parameters

NameTypeDescription
textStringthe text to render
fgColorthe color to render the text in
wrap_lengthIntthe maximum line width in pixels; 0 breaks lines only at newlines

Return

TypeDescription
SurfaceSurface instance, caller responsible for freeing; IsNull() is true on failure

RenderUTF8Shaded #

Render the UTF8 encoded text shaded

method : public : RenderUTF8Shaded(text:String, fg:Color, bg:Color) ~ Surface

Parameters

NameTypeDescription
textStringthe LATIN1 null terminated string to render.
fgColorthe color to render the text in. This becomes colormap index 1.
bgColorthe color to render the background box in. This becomes colormap index 0.

Return

TypeDescription
SurfaceSurface instance, caller responsible for freeing

RenderUTF8Solid #

Render the UTF8 encoded text blended

method : public : RenderUTF8Solid(text:String, fg:Color) ~ Surface

Parameters

NameTypeDescription
textStringthe LATIN1 null terminated string to render.
fgColorthe color to render the text in. This becomes colormap index 1.

Return

TypeDescription
SurfaceSurface instance, caller responsible for freeing

SetOutline #

Set the outline width; text is then rendered as an outline of that many pixels

method : public : SetOutline(outline:Int) ~ Nil

Parameters

NameTypeDescription
outlineIntoutline width in pixels, 0 for no outline

SetStyle #

Set the rendering style

method : public : SetStyle(style:Int) ~ Nil

Parameters

NameTypeDescription
styleIntFontStyle values OR'd together, such as FontStyle->TTF_STYLE_BOLD

SizeUTF8 #

Measure the size UTF8 text would have if rendered, without rendering it. Use it to center, right-align or fit a label.

method : public : SizeUTF8(text:String, w:IntRef, h:IntRef) ~ Int

Parameters

NameTypeDescription
textStringthe text to measure
wIntRefholder filled in with the width in pixels
hIntRefholder filled in with the height in pixels

Return

TypeDescription
Int0 on success, or a negative value on failure or for a closed font

Example

w := IntRef->New(); h := IntRef->New();
if(font->SizeUTF8("Accuracy: 0.97", w, h) = 0) {
x := (640 - w->Get()) / 2;
};