my-stbtt

A wrapper for using Sean Barrett's stb-truetype, a TrueType parser.


by Ingemar Ragnemalm 2023.


In the stb code collection, I found this TrueType parser. Compared to using more complex libraries, I found this very attractive. Just code!


The code does not interface to OpenGL itself, but comes with a demo that outputs ASCII (if I am not mistaken, it is a long time since I ran it the first time). I thought that I wanted something that plugs right into my code, unintrusively.


The API

=======


Just four calls:


void my_stbtt_init();


Initializes the library. Please do that!


stbfont *my_stbtt_initfont(char *fontName, float fontsize);


Loads a font.


float my_stbtt_print(float x, float y, char *text, stbfont *f);


Prints a string with the given font. Returns the final position so you can continue from there if you like.


void my_stbtt_set_color(float r, float g, float b);


Sets the color that the following drawing calls should use.


The demos

=========


Two demos are currently included:

my-stbtt-example.c


This draws a few strings with different font and colors.

This demo shows your options.


my-stbtt-bunny.c


This draws two strings and the "bunnyplus" 3D model. The demo shows how the text integrates with other graphics.


The fonts

=========


Four fonts are included:


halt.ttf

linux-libertine.ttf

qumpellkano12.ttf

schwaben-alt.ttf


All are found online clearly stated being public domain fonts.


Download First version as of 2024-03-01


This page is maintained by Ingemar Ragnemalm.