< index
< 2. Console emulator
< 2.1 Initializing the console

=====================================
2.1.2 Using a custom bitmap font
=====================================

This function allows you to use a bitmap font (png or bmp) with custom character size or layout.
It should be called before initializing the root console with initRoot.
Once this function is called, you can define your own custom mappings using mapping functions

C++ : static void TCODConsole::setCustomFont(const char *fontFile,int charWidth=8, int charHeight=8, int flags=0)
C   : void TCOD_console_set_custom_font(const char *fontFile,int char_width, int char_height, int flags)

ParameterDescription
fontFileName of a .bmp or .png file containing the font.
charWidth,charHeightSize of a character in the bitmap file.
flagsUsed to define the characters layout in the bitmap and the font type :
TCOD_FONT_LAYOUT_ASCII_INCOL (==0) : characters in ASCII order, code 0-15 in the first column
TCOD_FONT_LAYOUT_ASCII_INROW : characters in ASCII order, code 0-15 in the first row
TCOD_FONT_LAYOUT_TCOD : simplified layout. See examples below.
TCOD_FONT_TYPE_GREYSCALE : create an anti-aliased font from a greyscale bitmap

Different font layouts

ASCII_INROWASCII_INCOLTCOD

Different font types

standard
(non antialiased)
antialiased
(32 bits PNG)
antialiased
(greyscale)
Example :
Examples of fonts can be found in libtcod's fonts directory. Check the Readme file there.

C++ : TCODConsole::setCustomFont("standard_8x8_ascii_in_col_font.bmp",8,8,0);
      TCODConsole::setCustomFont("32bits_8x8_ascii_in_row_font.png",8,8,TCOD_FONT_LAYOUT_INROW);
      TCODConsole::setCustomFont("greyscale_8x8_tcod_font.png",8,8,TCOD_FONT_LAYOUT_TCOD | TCOD_FONT_TYPE_GREYSCALE);
C   : TCOD_console_set_custom_font("standard_8x8_ascii_in_col_font.bmp",8,8,0);
      TCOD_console_set_custom_font("32bits_8x8_ascii_in_row_font.png",8,8,TCOD_FONT_LAYOUT_INROW);
      TCOD_console_set_custom_font("greyscale_8x8_tcod_font.png",8,8,TCOD_FONT_LAYOUT_TCOD | TCOD_FONT_TYPE_GREYSCALE);