150 likes | 351 Views
Fonts. Andrew Williams A.Williams@bolton.ac.uk http://www.bolton.ac.uk/staff/adw1. AWFont Class. Very simple Very restrictive Can print strings… print_string(..) .. Or integers print_integer(..). Supplied Font. Bitstream Vera Sans, 10.5pt Nothing special about this It just looks nice
E N D
Fonts Andrew Williams A.Williams@bolton.ac.uk http://www.bolton.ac.uk/staff/adw1
AWFont Class • Very simple • Very restrictive • Can print strings… • print_string(..) • .. Or integers • print_integer(..)
Supplied Font • Bitstream Vera Sans, 10.5pt • Nothing special about this • It just looks nice • You can create your own font files • But there are rules that you MUST follow • There can be no exceptions to these rules
Bitmapped Font File • Created with a program called Bitmap Font Builder, by Thom Wetzel • See the link on my webpage • There is also a data file which gives character widths
Font Files • There are two in the example project • vera.bmp • vera.dat • These contain the bitmap and the character width data, respectively
Bitmap Font Builder Must be 256x256
Bitmap Font Builder Background must be black
Bitmap Font Builder Grid must be OFF
Bitmap Font Builder Must be only one font
Bitmap Font Builder You should accept the default size
Bitmap Font Builder You should left-justify your font
Saving Your Font Save as .BMP, eg arial.bmp
Saving Your Font Save font widths (Byte Format) eg arial.dat
Using AWFont • You can use as many as you like • You load each one like this (do this at the top of the program, but after SDL_SetVideoMode): font1 = new AWFont(“arial.bmp”, “arial.dat”); • Of course, the files must be in the project directory
Using AWFont • Printing something out: int endX = font->print_string(“SCORE: ", 10, 10); font->print_integer(score, endX, 10); • Parameters (for both) are: • What you want to print • X coordinate (screen, not world) • Y coordinate (screen, not world) • Do this in the game loop, sometime after drawing the background