If you only have a limited number of sizes, you could create a list of fonts like this:
import org.openrndr.application
import org.openrndr.draw.loadFont
fun main() = application {
program {
val fonts = List(10) {
loadFont(
"data/fonts/SourceCodePro-Regular.ttf",
4.0 + 5 * it * it,
"0123456789".toSet() // limited character set to use less memory
)
}
extend {
drawer.fontMap = fonts.random()
drawer.text(frameCount.toString(), 50.0, height - 50.0)
}
}
}
Approach 2
If you want to animate the scale you could create a high resolution font map and scale the text when drawing:
import org.openrndr.application
import org.openrndr.draw.loadFont
import org.openrndr.math.Vector2
fun main() = application {
program {
val font = loadFont(
"data/fonts/SourceCodePro-Regular.ttf",
600.0, // max size for text
"moz".toSet() // to avoid creating a huge texture full of unused chars
)
extend {
drawer.fontMap = font
drawer.translate(50.0, height / 2.0)
drawer.scale(0.01 + (frameCount * 0.001))
drawer.text("zoom", Vector2.ZERO)
}
}
}
Maybe some day there will be an alternative font rendering approach which is not based on font maps but on curves. Then one could write any size with the same font.
For performance reasons, when you load a font it creates a texture (the font map) with a set of characters. Later, when you draw text, it copies rectangles from this texture to the screen. This is much faster than drawing a lot of antialiased curves.
Some limitations with this approach: getting contours of letters, rotating or deforming text, exporting svg text or pen plotting text.
I asked about this is Slack:
edwin: it is actually not that hard to extract the glyphs using stb-truetype and convert them to shapes but to set proper texts with those glyphs is a different story