NAME
SDL3::TTF - TrueType Font support for SDL3
SYNOPSIS
use v5.40;
use SDL3 qw[:all :main];
use SDL3::TTF qw[:all];
TTF_Init() or die SDL_GetError();
my $font = TTF_OpenFont( 'C:/Windows/Fonts/arial.ttf', 48.0 )
or die SDL_GetError();
my $surface =
TTF_RenderText_Blended( $font, 'Hello, World!', 0, { r => 255, g => 255, b => 255, a => 255 } );
my $texture = SDL_CreateTextureFromSurface( $renderer, $surface );
TTF_CloseFont($font);
TTF_Quit();
DESCRIPTION
SDL3::TTF binds SDL_ttf, a companion library to SDL for working with TrueType (tm) fonts.
The library is a wrapper around the FreeType and HarfBuzz libraries, allowing you to use TrueType fonts to render text in SDL applications. Text can be rendered to a surface or directly to a texture, with control over the font size, style, hinting, and color. Complex scripts are shaped with HarfBuzz, fallback fonts extend the glyphs a font can draw, and outlines can be stroked with an arbitrary width.
Open a font with TTF_OpenFont( ... ) or TTF_OpenFontWithProperties( ... ), then render with the TTF_RenderText_*( ... ) and TTF_RenderGlyph_*( ... ) families. For styled, wrapped, and measured text, build a reusable TTF_Text object against a TTF_TextEngine and draw it into the renderer. Free fonts with TTF_CloseFont( ... ) and call TTF_Quit( ) when you are done.
There are a few examples in this distribution's eg/ttf directory.
Features
Each feature listed below is a tag you may use.
:all - SDL3_ttf Functions
This binds all functions, defines all types, and imports them into your package.
See the SDL3_ttf Wiki for documentation of the functions and types you will have access to with this import tag.
See Also
The project's repo: https://github.com/Perl-SDL3/
The SDL3_ttf Wiki: https://wiki.libsdl.org/SDL3_ttf/FrontPage
LICENSE
This software is Copyright (c) 2026 by Sanko Robinson.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
See the LICENSE file for full text.
AUTHOR
Sanko Robinson https://github.com/sanko