1. Alexander Malinin
  2. BearLibTerminal
  3. Issues
Issue #32 closed

Block-drawing chars weird for fonts with custom spacing

Steve Losh
created an issue

I might be doing this the wrong way entirely, let me know if so.

I'm trying to draw a menu window with bearlibterminal in a particular layer, but the docs say that only the very bottom layer can have a background. I read somewhere that the proper way to do this is to draw a "background" for my UI window with block-drawing characters on layer N, and then draw the actual menu text on N+1.

I also want to have two separate fonts: a square one for map tiles, etc, and a non-square one for text. So I set my cell size to 20x20 and defined two fonts:

  • square is size 20x20, spacing 1x1
  • tall is size 20x40, spacing 1x2

This mostly works, but it seems like the block characters aren't getting drawn properly for the tall font -- they only cover half of what they should. Example screenshot:


The code is using my Lisp wrapper but I'm not doing anything crazy in there.

Comments (6)

  1. Steve Losh reporter

    Poked around a bit more and it seems to be broken for anything non 1x1. Screenshot:


    In order, those fonts have spacing: 1x1, 1x2, 2x1, 2x2. The 1x1 is perfect, all the rest seem to always render the blocks as 1x1 (but render the letters correctly).

  2. Alexander Malinin repo owner

    Yes, this is a bug =(. Additional fonts use Block Elements characters of the primary font instead of their own version with a corresponding tile size.

    It may take some time to fix (I'm a bit busy right now) so there is a workaround for the time being (you probably figured this out already, but just in case): make a completely white .png of any size and load it as a tile with the required size, e. g. "0xE300: dot.png, resize=20x40". It might have been better to just make the whole background this way instead of painting it cell by cell but currently all tiles take exactly as much VRAM space as their dimensions are. So it is probably a bit wasteful to make huge sprites this way, though most of the hardware won't have any problem with this. I plan to make an optimization so that trivial filler/background tiles consume only as much resources as necessary.

  3. Steve Losh reporter

    I ended up working around it a different way. After some playing around I decided to set the base cell size to something quite small (e.g. 5x5) and then do all my actual drawing with larger fonts (e.g. 10x10 (spacing 2x2) for square stuff and 5x10 (spacing 1x2) for text). This gives me a bit more control.

    The only tricky part is that now I need to specify widths (like when calling print) in the base size. So (print 0 0 20 10 "foo") means to wrap the string to 20 base cells wide, not necessarily "20 characters" wide. But after using it, it's not actually that bad -- I don't really care exactly how many characters are on the line, as long as it fits properly.

    The original reason I was trying to use the block characters was to draw UI boxes, so now I just do that part of the drawing in the base units and everything works great.

  4. Log in to comment