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

Author Topic: Make sf::Font abstract, in order to make sf::Text re-usable for bitmap fonts  (Read 7875 times)

0 Members and 2 Guests are viewing this topic.

ecraven

  • Newbie
  • *
  • Posts: 9
    • View Profile
Hello :)

I've implemented my own BitmapFont class as well as my own Text class. If sf::Font were to be an abstract base class (with all of its functions virtual), I could just have re-used sf::Text. Is this something you are willing to discuss? I'm *not* suggesting any standard form of bitmap font support, just to change sf::Font so that it is possible to re-use sf::Text (which I think is impossible now).

Thanks for any comments!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
It has already been discussed, and as far as I remember, it was more or less agreed.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Mario mentioned it two weeks ago, was there another discussion? Because there, it was rather a border notice.

So don't hesitate to come up with some ideas :)
Is your BitmapFont class API very similar to sf::Font, which parts could be potentially reused?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Quote
was there another discussion?
Although they never mention it explicitly, other threads containing "bitmap font" in the "Feature requests" board suggest that I'm open to the addition of bitmap fonts through a unified interface.
Laurent Gomila - SFML developer

ecraven

  • Newbie
  • *
  • Posts: 9
    • View Profile
I just grab a texture which has all the letters. The constructor also takes a "mapping" from characters to indices. Otherwise I mostly copied the interface of sf::Font, returning an sf::Glyph, and not supporting italic/bold/...
I've never looked at other bitmap fonts, but I imagine it would be difficult to find a generic way to support them, but it might be possible to support at least the "letters on one texture" type (with some virtual functions for customisation).
If you are really interested, I could clean the code up some more and then post it. It's really nothing special though :)

For me, the most important point would be the change of making sf::Font a suitable base class to use, so that I can actually implement my own BitmapFont class without having to redo sf::Text and whatnot ;)
« Last Edit: June 26, 2014, 11:54:58 pm by ecraven »

Haze

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Github Profile
I just grab a texture which has all the letters. The constructor also takes a "mapping" from characters to indices. Otherwise I mostly copied the interface of sf::Font, returning an sf::Glyph, and not supporting italic/bold/...

Is your bitmap font a monospace one (all letters have the same width and height) ? If it's the case, your bitmap font class doesn't need to return a glyph, a simple texture sub rectangle is enough, and the API will be much simpler than sf::Font's one. A simple bitmap font is merely a tileset, and your bitmap texts are tilemaps.

Feel free to have a look at my implementation of BitmapFont/BitmapText if you want (I closely followed sf::Font/sf::Text semantics). See screenshot.

On a side note, sf::Font also supports bitmap fonts, and rendering at small size has been fixed in the upcoming 2.2 release, making custom BitmapFont classes quite useless (except if you really need an image).
« Last Edit: June 28, 2014, 11:39:22 pm by Haze »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
On a side note, sf::Font also supports bitmap fonts, [...] making custom BitmapFont classes quite useless (except if you really need an image).
What do you mean by that? What kind of bitmap font is supported by sf::Font?
The goal of bitmap fonts is to use well a bitmap = image.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Quote
What do you mean by that? What kind of bitmap font is supported by sf::Font?
Old font formats used by X (PCF, BDF) are bitmap fonts. So technically, yes, we support bitmap fonts since we can load these formats. But I've never seen anyone use these formats for bitmap fonts. I believe they are quite limited due to their age.
Laurent Gomila - SFML developer

Haze

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Github Profile
What do you mean by that? What kind of bitmap font is supported by sf::Font?
What Laurent said, and there's also bitmap fonts in ttf format (see http://www.dafont.com/fr/bitmap.php).
Many people who use bitmap fonts want a pixel perfect rendering (no hinting/blending/smoothing), something retro-looking which look nice at small size (the exact size designed for the font).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Quote
there's also bitmap fonts in ttf format (see http://www.dafont.com/fr/bitmap.php).
They just have a bitmap look, but I don't think they are bitmap fonts. TTF is a scalable format.
Laurent Gomila - SFML developer

Haze

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Github Profile
They just have a bitmap look, but I don't think they are bitmap fonts. TTF is a scalable format.
I'm not sure about this. They are rendered "pixel perfect" only if your sf::Text has the same character size the bitmap font was designed for. If you use a different size, the text is scaled and looks blurry.