Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Bitmap fonts?  (Read 13277 times)

0 Members and 1 Guest are viewing this topic.

Haikarainen

  • Guest
Bitmap fonts?
« on: July 16, 2011, 02:57:24 am »
Was thinking about writing my own bitmap font-class, and it came to my mind sfml should support this, what do you think?

Like have a tilemap in .png format, and a function to replace a certain color(like 255,0,0) to a userdefined color, so that SetColor would still work, therefore saving space and time :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Bitmap fonts?
« Reply #1 on: July 16, 2011, 09:47:35 am »
There are several ways of loading a bitmap font (especially, specifying where the glyphs are stored) -- and none of them is "standard". So which one should I use? I think it's too high-level and specific, I prefer to let users do their preferred way.

But why do you want to be able to use a custom bitmap font instead of a font file?
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Bitmap fonts?
« Reply #2 on: July 16, 2011, 11:11:43 am »
To make text fit in more to a game I'm working on. The text has a subtle gradient and outline, wich i think would be hard to accomplish using "regular" fonts. If i recall correctly their pixels are monochromatic/bitwise/1 or 0.

Maybe you are right, it sure is a wide topic :)

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Bitmap fonts?
« Reply #3 on: August 23, 2011, 02:20:36 pm »
This would be a big benefit to us. We've written our own, but bitmap fonts are so good because of the fact they're just artwork and you can do what you like.

We use them in our games a lot.
SFML 2.1

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Bitmap fonts?
« Reply #4 on: August 23, 2011, 02:30:18 pm »
Well it would remove the "simple" out of it but you could define a base-class or a callback or something to let the user define how to find character 'A' or 'z'.

That would let you "support" all different variations.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Bitmap fonts?
« Reply #5 on: August 23, 2011, 04:55:38 pm »
Quote
Well it would remove the "simple" out of it but you could define a base-class or a callback or something to let the user define how to find character 'A' or 'z'.

That would let you "support" all different variations.

And what about font metrics: kerning, line spacing, bouding rect, ...? There are really too many parameters to load in addition to the image itself.

And how would I handle different character sizes with the same font, which is trivial with the current API?
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Bitmap fonts?
« Reply #6 on: August 23, 2011, 05:17:39 pm »
Hmm well if there's a base class for it then it's up to the developer to implement it. But it would still be just like if the user developed it himself. I guess the "bonus" would be that sf::Text would be able to use the bitmap font directly as there would be a base class. But that's probably the only advantage as well.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Bitmap fonts?
« Reply #7 on: August 28, 2011, 08:25:03 pm »
True. I might just as well share our bitmap font stuff. All the metrics are loaded in from an XML file.
SFML 2.1

bobingabout

  • Newbie
  • *
  • Posts: 47
    • View Profile
Bitmap fonts?
« Reply #8 on: September 05, 2011, 02:18:33 pm »
I definitely think bitmap fonts would be a good feature. I was thinking of trying to implement my own, but I'm not sure where to begin with SFML yet (I write a set of functions to do it with SDL, but its just too slow, so I'm thinking of switching to SFML). I was thinking maybe sprites would be the best way to start with it, but i'm not sure how they work yet (since i've only been reading through a little informatino so far).

I do agree that this is something a little too difficult to create a function for, because there's no real standardised format, i wrote my own in SDL, where the bitmap is basicly a 16x16 grid corrosponding to the ASCII code. the char height is image height over 16, the widths are defined in a seperate hex edited file, 256 bytes in size, each byte basicly holding the value for the width of the char in pixels inc space.


though, I did see "Easy manipulation of graphical text through bitmap fonts" on the list of features on the main page, can anyone enlighten me on this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Bitmap fonts?
« Reply #9 on: September 05, 2011, 02:52:53 pm »
Quote
I definitely think bitmap fonts would be a good feature. I was thinking of trying to implement my own, but I'm not sure where to begin with SFML yet

The simplest solution is too:
- create your own bitmap font class, with the same public functions as sf::Font
- copy sf::Text (sf::String in SFML 1.6) and simply change its sf::Font member to be a YourBitmapFont

Quote
I do agree that this is something a little too difficult to create a function for, because there's no real standardised format

Maybe I should just pick up a popular format and support it directly in sf::Font. Then it's up to people to convert if they use something else, but at least they have a way to load their own bitmap fonts.

Quote
though, I did see "Easy manipulation of graphical text through bitmap fonts" on the list of features on the main page, can anyone enlighten me on this?

It's still bitmap fonts, it's just that the bitmaps are not loaded from images, they are generated internally.
However it's probably not a relevant information, it's an implementation detail so people shouldn't care about it. I should rather write "Easy manipulation of graphical text, generated from truetype font files".
Laurent Gomila - SFML developer

omeg

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • http://omeg.pl/
Bitmap fonts?
« Reply #10 on: September 05, 2011, 03:20:24 pm »
Make sure to not limit character number to only ASCII range if you end up implementing that. :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Bitmap fonts?
« Reply #11 on: September 05, 2011, 03:28:49 pm »
Of course, sf::Font supports full Unicode so it would be stupid to limit the external bitmap fonts to ASCII ;)
Laurent Gomila - SFML developer

tobybear

  • Newbie
  • *
  • Posts: 27
    • View Profile
Bitmap fonts?
« Reply #12 on: January 20, 2012, 01:08:14 pm »
Many people use the format exported from Angelcode's BitmapFont creator tool: http://www.angelcode.com/products/bmfont/
While this tools allows converting a TTF->image (like many other similar freeware tools), the file format (kerning/offset/postion) is often also used for regular "rectangular" bitmap fonts (or is automatically applied on loading).
I once wrote a simple loader for SFML 1.5 for Angelcode format and also regular bitmap fonts, but I think the source is lost.
But implementation is not that complicated, here are some examples in DirectX / OpenGL:
http://www.chadvernon.com/blog/resources/managed-directx-2/bitmap-fonts/
http://www.gamedev.net/topic/330742-quick-tutorial-variable-width-bitmap-fonts/
http://sourceforge.net/projects/oglbmfont/

And here is another bitmap font creator with C++ loading sources included:
http://www.codehead.co.uk/cbfg/

I will probably write my own bitmap font class in SFML2 in the next 1-2 weeks (using the new VertexArrays!) with the option of importing at least the Angelcode format as well as simple images with fixed character height/width (like in oldschool amiga demos :-).
If there is any interest, I might publish this class as well for you to play around with :)

capz

  • Newbie
  • *
  • Posts: 29
    • View Profile
Bitmap fonts?
« Reply #13 on: February 07, 2012, 03:42:03 am »
..why not just use a bitmap-styles ttf font, or use an app to create a font in a particular style and use the standard sf fonts? Rolling your own bitmap font code is so simple, I wouldn't add it to sfml. For anything beyond simple, there's sf fonts

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Bitmap fonts?
« Reply #14 on: February 08, 2012, 05:36:28 pm »
It might be a lot harder to match the "virtual pixels" of a TTF font with the actual pixels on screen. It could as well cause sub pixel artifacts, blocky/weird scaling issues etc.

And (imo the biggest difference): It's a lot harder to embed glyphs and icons when using a TTF font. Sure, it's possible, but it's a lot easier drawing these as special glyphs "inline" with the other text.