Glimmr Drawing Commands

version 2/101030 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Section: Extending bitmap fonts

    There are also special facilities for extending a bitmap font if it is missing characters we need. This doesn't require us to edit the original font in any way, and the ease of creating bitmap characters makes it relatively painless. In fact, this is why the Glimmr Bitmap Font has fewer glyphs than Bitmap Image Font--because it is far easier to create new bitmap glyphs than new image ones. (It's also easy to edit a bitmap glyph by directly changing the bitmaps in the glyph map. If you do this to someone else's font, be sure to change the colophon to give yourself credit.)

    Extending bitmap fonts is a two-step process. First, we need to add our new glyphs to the font's glyph map. The "starting the virtual machine" activity is probably the best place to do this. Here is a glyph for a happy face, which we will place at character code 1:

        After starting the virtual machine:
            Add {
                1, [This is the character code]
                0, 1, 1, 1, 1, 1, 0,
                1, 0, 0, 0, 0, 0, 1,
                1, 0, 1, 0, 1, 0, 1,
                1, 0, 0, 0, 0, 0, 1,
                1, 0, 1, 1, 1, 0, 1,
                1, 0, 0, 1, 1, 0, 1,
                1, 0, 0, 0, 0, 0, 1,
                0, 1, 1, 1, 1, 1, 0 } to the glyph map of Glimmr C&C.

    Never use any syntax but the "Add {} to the glyph map of ..." shown here to extend glyph maps. The order of glyphs in the glyph map is of critical importance, and new glyphs must always be added *after* all earlier glyphs.

    We must also then extend the typeface's font table so that the glyph can be drawn to the screen. We do this by looking at the font extension, noting the name of the font table, and putting a table continuation in our own code. Note that the order in which glyphs are listed in the table must be the same as the order in which they are listed in the glyph map! Example:

        Table of Glimmr C&C Parameters (continued)
      glyph  char  index  width  height  yoffset  advance  
      "happy face"  1  2724  7  8  1  8  

    (If you haven't already read the preceding section, on creating bitmap fonts from scratch, do so before continuing--it explains the makeup of the font table, including the meaning of the index column.)

    2724
    Note that the "index" column has been left blank. Just as when we create a new font, we will need to provide index numbers for each new glyph we add to the font; but we don't want to have to count the characters in the font. There are in fact two ways to do this. If we include this code in our game:

        set blank indices for Glimmr C&C

    ...the game will silently and automatically correct the font table, adding the needed index numbers for us. We can leave this code in our game and, at the cost of a little extra time at startup, this will get things working with no additional effort, e.g.:

        After starting the virtual machine:
            Add {
                1, [This is the character code]
                0, 1, 1, 1, 1, 1, 0,
                1, 0, 0, 0, 0, 0, 1,
                1, 0, 1, 0, 1, 0, 1,
                1, 0, 0, 0, 0, 0, 1,
                1, 0, 1, 1, 1, 0, 1,
                1, 0, 0, 1, 1, 0, 1,
                1, 0, 0, 0, 0, 0, 1,
                0, 1, 1, 1, 1, 1, 0 } to the glyph map of Glimmr C&C;
            set blank indices for Glimmr C&C.

    But we can also use the same command on a temporary basis to fix the table. To see the calculated index numbers, simply remove the silently from the above phrase:

         set blank indices for Glimmr C&C.

    This will output any changes made to the screen. We can then type the proper index numbers into our table and remove the "set blank indices" instruction from the source code. Optionally, we can also verify that both old and newly assigned index numbers match the glyph map (we would not want to do this in a released game, but it potentially useful for debugging):

        set blank indices for Glimmr C&C, verifying glyph map.

    Finally, "set blank indices" can also output the *entire* table to an external text file, which is expected to be useful only if we are designing our own font, or heavily modifying an existing one:

        set blank indices for Glimmr C&C, verifying glyph map and writing table to disk.

    If you run your game in the Inform IDE, the external file should be saved to your project folder.