-
Notifications
You must be signed in to change notification settings - Fork 74
Tutorial 06 Writing text
Oliver Simmons edited this page Feb 5, 2022
·
1 revision
Writing text to the screen is easy with SDL_ttf.
See Tutorial 04 - Drawing an image to initialize the window and renderer.
Download full example: 06-text.tgz
As always, load the library separately.
local ttf = require("SDL.ttf")We now want to load the library.
assert(ttf.init())Now that we loaded the SDL_ttf library, we must open a font before writing text. A path to a .ttf file must be specified.
local font = assert(ttf.open("DejaVuSans.ttf", 10))The functions Font:renderUtf8 and friends creates surfaces which must be converted later.
local s = assert(font:renderUtf8("Lua-SDL2", "solid", 0xFFFFFF))Convert the surface to texture & display.
local text = rdr:createTextureFromSurface(s)
-- This would normally be called in your main loop
rdr:clear()
rdr:copy(text)
rdr:present()