Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro.pas - Problems with Using a Bitmap Font

This thread is locked; no one can reply to it. rss feed Print
Allegro.pas - Problems with Using a Bitmap Font
RPG Hacker
Member #12,492
January 2011
avatar

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):

rpghackerfontrmg2000.png

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_load_bmp (filename: STRING; palette: AL_PALETTEptr): AL_BITMAPptr; CDECL; EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'load_bmp';
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.

#SelectExpand
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[...]

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

EDIT:
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!

J-Gamer
Member #12,491
January 2011
avatar

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.

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

RPG Hacker
Member #12,492
January 2011
avatar

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.

Go to: