How Hard Can Text Rendering Really Be?
Today's goal: Lay the groundwork for TrueType font rendering!
Updates
- Created a Discord for Flux Harmonic: https://discord.gg/ryy97Rdw
- PNG saving now works (Thanks to
libspng
's author Randy for stopping by!) - I added some code for rotating and scaling rendered textures
- Also made the preview area center itself and be scalable
Rendering TrueType fonts with OpenGL
Today we'll be using the long-lived FreeType library to load up a TrueType font so that we can extract glyphs for each letter, turn them into OpenGL textures, and render them to the screen.
Things we'll probably have to deal with:
- Storing information about characters of different sizes
- Kerning, to a basic degree (the space between characters)
- Locating fonts by name using FontConfig (probably later)
We won't be adding things like text wrapping or alignment (yet), this code will just render a string from left to right.
Tasks
DONE Use the FreeType library to load a font
DONE Render glyphs to OpenGL textures
DONE Write a function that can render a string by indexing the texture for each letter
Notes
The code for this stream can be found here:
https://github.com/FluxHarmonic/flux-compose/commit/2bbc4e0c65ec45bf974456250f368b28b72622bf
References