Bitmap cannot be displayed

I tested that the official font_draw-over_image displayed normally, and then I tried to replace my game resource image for testing. However, when configuring the relevant information, it still couldn’t be displayed

Attached PNG images for testing

To use TCasteBitmapFont, your font image must include more glyphs.

When we decide what part of the image we use to display a glyph, we simply do this:

    CharIndex := C - Ord(' ');
    ImageX := CharIndex mod FImageColumns;
    ImageY := CharIndex div FImageColumns;

Where C is Unicode character number. For regular ASCII characters, Unicode and ASCII order is the same.

( This is code from CGE implementation, castle-engine/src/fonts/ at master · castle-engine/castle-engine · GitHub ). There is no way (right now) to tell TCasteBitmapFont that “the first glyph is for -, next one for 0 etc.” )

The solution is just to enlarge your image, to include space for other glyphs, up to the digits that you want. Of course the glyphs can be empty (or contain just ? or anything else, copied over and over) if you don’t really plan to display them.

You can take a look at sample castle-engine/examples/fonts/font_draw_over_image/data/null_terminator_0.png at master · castle-engine/castle-engine · GitHub to see the glyphs that need to be included before digits – you need to leave space for 16 glyphs, if I count right.

Note that null_terminator_0.png has white text over transparent background, it’s not really displayed in a useful way in a browser :slight_smile: But you can download it and inspect e.g. in GIMP to see what’s going on.

Let me know if this explanation is helpful and enough for you to deal with this :slight_smile:

1 Like

Thank you very much. I have a rough idea of the reason