# Bitmap font rendering

- The bitmap font structure
- sge_BF_OpenFont
- sge_BF_CreateFont
- sge_BF_CloseFont
- sge_BF_SetColor
- sge_BF_SetAlpha
- sge_BF_GetHeight
- sge_BF_GetWidth
- sge_BF_TextSize
- sge_BF_textout
- sge_BF_textoutf
- sge_BF_input

The bitmap font structure

    typedef struct{
       ...
    } sge_bmpFont;

When working with BF functions you must give a pointer to the font structure. To open a new font (structure) use sge_BF_OpenFont() and when finished use sge_BF_CloseFont().
sge_bmpFont* sge_BF_OpenFont(char *file, Uint8 flags)
Opens the given font file. Returns a pointer to the new font.
Flags: (may be ORed, eg. SGE_BFTRANSP|SGE_BFSFONT)
SGE_BFTRANSP - Transparent (should usually be set).
SGE_BFNOCONVERT - Don't convert font surface to display format for faster blits.
SGE_BFSFONT - If you enabled support for SDL_img when compiling SGE you can also set the SGE_BFSFONT flag, this enables you to load Karl Bartel's SFont files.
SGE_BFPALETTE - Converts the font surface to a palette surface (8bit). Don't do this on color fonts or SFonts! Blits from the font surface will be a bit slower but sge_BF_SetColor() will be faster (O(1) instead of O(n^2)).
sge_bmpFont* sge_BF_CreateFont(SDL_Surface *surface, Uint8 flags)
Same as sge_BF_OpenFont() but reads the font data directly from a surface.
void sge_BF_CloseFont(sge_bmpFont *font)
Removes font from memory.
void sge_BF_SetColor(sge_bmpFont *font, Uint8 R, Uint8 G, Uint8 B)
Changes the color of the font to (R,G,B). Doesn't work on 'color fonts' or SFonts. Use SGE_BFPALETTE when opening the font if you're going to use this function often.
void sge_BF_SetAlpha(sge_bmpFont *font, Uint8 alpha)
Sets the alpha level of the font. Doesn't work on SFonts with alpha channels.
Sint16 sge_BF_GetHeight(sge_bmpFont *font)
Returns the height of the font.
Sint16 sge_BF_GetWidth(sge_bmpFont *font)
Returns the width of one character in the specified font. Doesn't work on SFonts.
SDL_Rect sge_BF_TextSize(sge_bmpFont *font, char *string)
Returns the width (.w) and height (.h) of the string with the given font.
SDL_Rect sge_BF_textout(SDL_Surface *surface, sge_bmpFont *font, char *string, Sint16 x, Sint16 y)
Renders the given string on surface with the given font. (x,y) is the position of the left top corner. Does lock and update the surface. Returns the postion and size of the rendered string. Does lock and update the surface. Does respect clipping.
SDL_Rect sge_BF_textoutf(SDL_Surface *surface, sge_bmpFont *font, Sint16 x, Sint16 y , char *format, ...)
Just as sge_BF_textout() but with the same syntax as printf().
sge_BF_input

- int sge_BF_input(SDL_Surface *screen,sge_bmpFont *font, char *string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y)
- int sge_BF_inputAlpha(SDL_Surface *screen,sge_bmpFont *font, char *string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y, int Alpha)
- int sge_BF_input_UNI(SDL_Surface *screen,sge_bmpFont *font, Uint16 *string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y)
- int sge_BF_inputAlpha_UNI(SDL_Surface *screen,sge_bmpFont *font, Uint16 *string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y, int Alpha)

These function handle keyboard input and shows the result on screen. Works in the same way as sge_tt_input() but always preserves the background and (x,y) is the top left corner of the rendered text string.
Flags: (may be ORed, eg. SGE_IDEL|SGE_INOKR)
0 - Default
SGE_IDEL - Delete text on exit.
SGE_INOKR - No keyrepeat (you can then use SDL_EnableKeyRepeat() yourself).
Note: This function will block your program! Use the text classes if you want more control (see the example).

Copyright © 1999-2003 Anders Lindström
Last updated 030808