Allegro.pas - Problems with Using a Bitmap Font
RPG Hacker

Hi there,
I've just recently started programming a game in Allegro.pas (I chose the Pascal version because Pascal is the only programming language I'm familiar with so far). Right now I'm working on setting up all the mandatory stuff (Allegro initilization, config file etc.). Here I'm have encountered a problem with using a Bitmap Font, which I can't solve. First of all the font itself (created with an Allegro font editor):


The pink part is color 0, the yellow part color 255 and it's saved as 256-color-BMP-image (even though ImageShack seems to automatically convert it to PNG when uploading). At first I tried the "simple" version:

FUNCTION al_load_bitmap_font (filename: STRING; palette: AL_PALETTEptr; p: POINTER): POINTER;

Here I had the problem that I didn't even know what the pointer p is supposed to be. It's not mentioned in the documentation. Additionally it crashed (I just tried to use "nil" for p). Next I tried the method with first loading a bmp and then grabbing a font from it.

FUNCTION al_grab_font_from_bitmap (bmp: AL_BITMAPptr): AL_FONTptr; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'grab_font_from_bitmap';

Loading the BMP file works just fine. Even displaying it using the al_blit function works as expected. However, whenever my program gets to the grab_font part of my code it crashes, displaying random errors messages I don't understand. I've read the according entries in the documentation over and over again, but I just couldn't find the mistake. Can someone help out? Here are the portions of my code that (I think) matter.

1program RPGHacker_LPYGEntry; 2 3uses 4 sysutils, 5 allegro, 6 alfile; 7 8var 9 FontRMG2000 : AL_FONTptr; 10 11 12 13function GameInit : boolean; {Game initilization function} 14 var [...] 15 BitmapPtr : AL_BITMAPptr; 16 17begin 18 [Allegro initilization routines, including al_set_gfx_mode, go here] 19 [...] 20 21 Path := ExtractFilePath(ParamStr(0)) + '\bitmap\RPG_Hacker-Font_RMG2000.bmp'; 22 BitmapPtr := al_load_bmp(Path,@al_default_palette); 23(* This here is where the crash occures *) 24 FontRMG2000 := al_grab_font_from_bitmap(BitmapPtr); 25end; 26 27[...]

The error says "Project [Projectname].exe raised exception class 'External: SIGSEGV'." This seems to be the default error I get whenever something goes wrong.

Problem solved. Turned out from some color editing in an external program the format of my font changed to a format unreadable by Allegro. Can't really explain this, but oh well. At least it works now!


SIGSEGV isn't the default error. It is a very common one. It means that you've tried to access something you shouldn't. Like going out of bounds in an array.

RPG Hacker

I forgot to add "The default error I get". What I meant is that this always seems to be the cause when something goes wrong for me. :P

Anyways, as mentioned in the EDIT, the problem is fixed now. After exporting the font with the font editor, editing it with any graphics editor seems to break it for Allegro. However, I've found out that increasing the color depth of the image to 24-Bit fixes it again.

Thread #605972. Printed from