Loads a TrueType/OpenType font (.ttf/.otf) at a given pixel height.
Takes path (path to the font file) and pixelHeight (the size to render glyphs at, in pixels).
Returns a font handle (positive integer for success, 0 for failure).
2D Overlay
Parameters & Returns
Parameters
pathString
pixelHeightInt
Returns
Int
Quick Summary
Loads a TrueType/OpenType font (.ttf/.otf) at a given pixel height.
Takes path (path to the font file) and pixelHeight (the size to render glyphs at, in pixels).
Returns a font handle (positive integer for success, 0 for failure).
Technical Exegesis...
Loads a TrueType/OpenType font and returns a normal font handle - the same kind of handle b2dLoadFont returns, so every text function (b2dDrawText, b2dDrawTextEx, b2dGetStringWidth, b2dGetStringHeight, b2dGetFontWidth, b2dGetFontHeight, b2dFreeFont) works with it.
Loads a TrueType/OpenType font and returns a normal font handle - the same kind of handle b2dLoadFont returns, so every text function (b2dDrawText, b2dDrawTextEx, b2dGetStringWidth, b2dGetStringHeight, b2dGetFontWidth, b2dGetFontHeight, b2dFreeFont) works with it. Unlike a bitmap font, a TTF font rasterises its glyphs on demand into a growable texture atlas, keyed by Unicode codepoint, so it renders real Unicode text - including accented Latin, Cyrillic, Greek and CJK (Japanese/Chinese/Korean) - as long as the loaded font contains those glyphs.
Text passed to the draw and measure functions is decoded as UTF-8 (desktop) / by codepoint (web), so a multi-byte character is treated as one glyph with its own advance, not several. Source-file string literals in UTF-8 work directly.
Size: each pixelHeight is its own font handle and its own atlas (glyphs are crisp - a single atlas is never scaled). Load the same file at several sizes for small UI text vs large titles.
Common patterns: title=b2dLoadTTF("Media/heading.ttf", 48); body=b2dLoadTTF("Media/body.ttf", 20); cjk=b2dLoadTTF("Media/NotoSansSC.ttf", 32). Then draw with b2dDrawText as usual.
Platforms: desktop (DirectX 12) rasterises with stb_truetype; web (WebGPU) rasterises the same font via the browser after loading it as a FontFace. On the web the font file loads asynchronously - text functions return nothing / a width of 0 until it is ready, so gate on b2dGetStringWidth("A", font) > 0 if you need to know it has loaded (the same idiom used for bitmap fonts and images on web).
Error handling: returns 0 if the file is missing or not a valid font. Safe to continue - a 0 handle is ignored by the draw functions.
Related: b2dLoadFont loads a pre-rendered bitmap atlas font instead, b2dFreeFont releases the font (and its atlas), b2dDrawText / b2dDrawTextEx render with the font, b2dGetStringWidth / b2dGetStringHeight measure a string in the font.