Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » al_load_bitmap_font

This thread is locked; no one can reply to it. rss feed Print
al_load_bitmap_font
duncan perham
Member #15,403
November 2013

So im playing arround with this function. But the documentation is very limited. Ive kind of got something working, but nothing usable at the moment.

Can someone please tell me how the bmp is meant to be layed out, I get it that is layed out in ASCII, 32(spc),(33)!,(34)",(35)# etc.

But how is it layed out in the file and what are the sizes etc, at present I have it layed out as a 64x64 images, in a grid of 16x16. (1024X1024). which is 256 characters. but I guess im only trying to get 128.

Any advice on how to lay it out and size restrictions would be nice.

Kris Asick
Member #1,424
July 2001

You actually don't lay it out as a grid. :o

Here's an example of an Allegro 4 font I've made (which technically will work in Allegro 5 though it may look odd for reasons I will go into in a moment):

{"name":"610264","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/0\/7077f288e49e047797eae8cd7c1f65a1.png","w":640,"h":480,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/0\/7077f288e49e047797eae8cd7c1f65a1"}610264

...and here's how it works:

  • Most of the image will be a "background" colour to represent unused whitespace. This colour will act to "frame" all of your glyphs and it's vitally important that the top-left-most pixel (0,0) be this colour. You generally want to start your font either at (1,1) or anywhere else. With Allegro 4, you would typically set this to any colour not used in your font, but because Allegro 5 uses hardware accelerated graphics, and because this can result in bleed if you do any texture filtering, I recommend doing a flood-fill on this when your font is done to make it ALMOST completely transparent, using an alpha value of 1/255 so that when the glyphs are rendered, if there is any bleed it will be completely unnoticeable.


  • The glyphs themselves only need to be arranged so that the tops of each glyph are aligned vertically. Beyond that, you can make the glyphs any size and any width. They do NOT need to be aligned horizontally. (I just do that to make it easier for me to know where I am in the sequence when actually drawing them.)


  • Any colour other than the background colour will be treated as a glyph, thus you just draw out your glyphs inside boxes. In Allegro 4, the background in your boxes would typically be black for being masked out, but in Allegro 5, you generally want this background to be 100% transparent with 0 alpha.

And... that's all there is to it! Just remember to have each glyph surrounded by the framing background colour and it should work fine! ;)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

duncan perham
Member #15,403
November 2013

Thanks for that, thats cleared up a few questions, now to see if I can get it to work :).

Elias
Member #358
May 2000

Are you sure the background color is copied over into the font? As far as I know the actual texture uses complete transparency instead so there can be no bleed and it therefore does not matter at all which color you use.

--
"Either help out or stop whining" - Evert

Kris Asick
Member #1,424
July 2001

Elias said:

Are you sure the background color is copied over into the font? As far as I know the actual texture uses complete transparency instead so there can be no bleed and it therefore does not matter at all which color you use.

It actually depends on how the video card reads texture data at the edges of a polygon when drawing it but yes, bleed can occur in this case because the individual glyphs of a bitmap font are not separate textures, rather they are pieces of the larger texture they came from, thus the boundary pixels used to define the font glyphs in the first place are still there. :P

Bleed ONLY occurs with any texture filtering other than nearest neighbour, as all other methods blend between nearby texels, whereas nearest neighbour is incapable of exceeding the boundaries set when pulling from the source texture.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Elias
Member #358
May 2000

Hm, according to the source code the original bitmap is not used though, so there should be nothing to bleed from... so this sounds like a bug.

--
"Either help out or stop whining" - Evert

Kris Asick
Member #1,424
July 2001

Really? I know the font system doesn't create separate textures for each individual glyph as that would slow font rendering down tremendously, so... what does it do then? Does it copy the glyphs to a brand new blank texture to bypass the chance of any sort of bleed happening?

The thing is, I always assumed A5's font system worked similar to the sub-bitmap system, and when you make sub-bitmaps of a larger bitmap with A5 and start doing scaling and rotating with texture filtering, you get bleed, so I assumed the same thing would happen with fonts and thus made my fonts accordingly.

So... apologies if I'm wrong about the font system working the way I thought it did. ::)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Elias
Member #358
May 2000

It creates a copy of the bitmap you pass and calls al_convert_mask_to_alpha on that copy, with the color at position 0/0.

--
"Either help out or stop whining" - Evert

Kris Asick
Member #1,424
July 2001

I didn't know al_convert_mask_to_alpha was a thing. :o

Learn something new every day! ;)

Like today especially, I learned ALLLLLLLLL kinds of fun facts! ...99% of which are likely pure BS because APRIL FOOLS! ::)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Go to: