0 votes

I always hand-make the fonts for my games rather than use pre-existing fonts. In the past, when using the Allegro libraries, this was done simply by formatting the bitmaps in a particular way and using Allegro's tools to quickly parse the bitmap's glyphs into Allegro's own internal font format.

However, I'm at a loss as to how to do this with Godot. From what I've read, the BitmapFont object in Godot uses the "BMFont" file format, but EVERY tool I've found online which exports to this format doesn't actually support importing an existing bitmap and working with it, instead opting to generate bitmaps out of TTF files, which doesn't help me at all. :(

So yeah, how do I get my own hand-crafted bitmap fonts loaded into Godot as BitmapFont objects, and if I have to use a third party tool to do this, what tool would even work for this?

in Engine by (27 points)

2 Answers

0 votes

Try FontForge. It can apparently open BitMap fonts, and I know it can edit glyphs and export to Godot.

You can create a Godot DynamicFont Ressource inside a file (New Resource option in the FileSystem dock), and set it's Font/Font Data property to a .ttf file (which is an export fileformat supported by FontForge).

Finally, you can set the global Godot font in the project settings, under GUI/Theme/Custom Font.

by (2,484 points)

Hmm... FontForge is definitely more geared towards vector fonts instead of bitmap fonts. The bitmap font features it has are primarily related to actual font files with bitmaps encoded into them, as opposed to loading in raw bitmaps and working with them, which you CAN do... on a per-glyph basis, so that wouldn't really be any faster for me than hand-typing the BMFont files from scratch with all the appropriate coordinates for each glyph... which seems to be the route I'm going to have to take at this rate. Not the end of the world but understandable given how few people hand-craft their fonts in bitmap form. :P

+1 vote

You can create BitmpFont from a hand-made image by using add_texture and add_char function from GDScript:

e.g. monospaced font with 10x10 chars placed horizontally in the image:

var font = BitmapFont.new()
var texture = load("res://font_image.png")
var chars = "ABCDEF...."
for i in range (0, chars.length()):
    font.add_char(chars.ord_at(i), 0, Rect2(10 * i, 0, 10, 10), Vector2(0, 0), 10)

And apply it to the controls using:

$Control.add_font_override("font", font)
by (358 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.