KelvinShadewing / brux-gdk

Free runtime and development kit using SDL and Squirrel
GNU Affero General Public License v3.0
39 stars 20 forks source link

Replace SDL2_ttf with bitmap fonts #3

Closed KelvinShadewing closed 5 years ago

KelvinShadewing commented 7 years ago

SDL2_ttf overrides scaling modes and requires the creation of both a new surface and texture every time text is rendered. Using a bitmap font will allow text to render faster and also add useful features like getting the length of a string in pixels for use with word wrap and games that use typing text boxes.

Other non-essential, but still interesting, features could be added down the road, like animated text and Minecraft-like color blended highlighting.

Bitmap fonts will work by taking a sprite and scanning each frame for columns that are fully transparent to store character boundaries. Any sprite could potentially be used as a font. Also, a simple flag could be used to determine whether or not a font is displayed as monospace without the need to load separate sprites, since it will use stored numbers that can be ignored instead of a specific color key like NFont.