Easy usage of bitmap fonts when using SDL
- Size
- 1.2M (1,251,479 bytes)
- Added
- 2026-11-20 02:43
- Downloads
- 2
- Long Description
- -----------------------------------< SFont >------------------------------------ License: GPL or LGPL (at your choice) Author: Karl Bartel <karlb()gmx.net> WWW: http://www.linux-games.com/sfont/ Usage: 1. Load a font and place it in an SDL_Surface *. If your are using the SDL_image library you can do this with Font = IMG_Load("filename"); 2. Initialize the font by using InitFont(surface *Font); 3. Now you can use the font in you SDL program. Please take a look at SFont.h to get info about the funtions. For more usage examples, have a look at the included example files. File Format: The font file can be any type image file. The characters start with ASCII symbol #33. They are seperated by pink(255,0,255) lines at the top of the image. The space between these lines is the width of the caracter. Just take a look at the font, and you'll be able to understand what I tried to explain here. Example for the font file format: ____ _____ _____ _____ <- This is the pink line at the top # ##### #### # # # # # # # # # # # # ##### # ##### # # # # # # # # # # ##### #### |----| Width of the character |----------| Part of the font surface that is beeing blitted How to create Fonts: The easiest way to create a new font is to use the GIMP's Logo function. Use the following string as text (ASCII 33-127 with escape sequences and spaces between the letters): ! " # % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? () A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ In most other applications, you can just use the ASCII charakters without escape sequences: ! " # % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? () A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ Now you have to add the pink line above the font. You can either do this manually, or let SFontMaker (http://nostatic.org/sfont/) do the work for you. SFontMaker doesn't always generate the optimal soultion, but it's usually good enough, and it provides a great starting point for manual font tweaking. ChangeLog: 2.03 Changes in C++ Wrapper by Lion Vollnhals: fixed typo in "SFont_TextHeighT" call fixed forgotten ',' in function Write fixed parameter order in function Write changed exception class to std::runtime_error which is derived from std::exception because of - standard conformance - the additional functionality of class Exception isn't used in the code - the code of class Exception uses non-C++ C code facilities, which are type unsafe and potentially dangerous - to remove the .cpp (object) file added overloaded functions to support the standard std::string class Also the class name has been changed to SFont and the Write method has been renamed to write 2.02 Readded GPL/LGPL license choice (it got lost somehow when I put out the 2.0 version) Changes by Florian Hufsky <fhufsky()phorus.at> (http://jnrdev.weed-crew.net) : Added a character list without escape sequences to the readme. added link to SFontMaker removed some confusing, outdated comments SFont.h 2.01 Fixed a compilation problem with older gcc versions (parse error before cyan) Added a SFont_Font cast before malloc, to make more compilers happy. 2.0 All changes in this version were done by Matthias Braun. Yhis version breaks compatability in favor of a cleaner API! Changes in detail: - SDL.h is an external library so we should do #include <SDL.h> (same goes for string.h) - prefixed all functions with SFont_, this is good style to avoid naming conflicts with other packages which might already