Author Topic: Bitmap-Font Maker  (Read 16709 times)

0 Members and 1 Guest are viewing this topic.

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: Bitmap-Font Maker
« Reply #20 on: April 17, 2012 »
Great. Thanks for the detailed info Hellfire, much appreciated.
raizor

Challenge Trophies Won:

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 1217
  • Karma: 230
    • View Profile
    • Homepage
Re: Bitmap-Font Maker
« Reply #21 on: April 17, 2012 »
Looks like a great little tool!  :clap:
www.kirl.nl
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: Bitmap-Font Maker
« Reply #22 on: April 17, 2012 »
Nice one Hellfire, I will have a play later.  :goodpost:

Offline Voltage

  • Professor
  • Pentium
  • *****
  • Posts: 857
  • Karma: 53
    • View Profile
Re: Bitmap-Font Maker
« Reply #23 on: April 18, 2012 »
Nice work Hellfire, karma++ 

I've used this tool before, and I'll use it again.

To get some better precision I do a re-vectorization of the anti-aliased bitmap using marching squares.
Otherwise (when working with whole pixel distances only) you would need to increase the rendering size drastically (which makes the search incredibly slow).

Any chance I could get an explanation like I was 5? :)

Another question regarding the shader that would be used to draw these distance field fonts.  It would look up a texel, and it would know how far from the font it is by this lookup.... but what to do with that info?  Do I draw here or not?
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Bitmap-Font Maker
« Reply #24 on: April 18, 2012 »
To get some better precision I do a re-vectorization of the anti-aliased bitmap using marching squares.
Any chance I could get an explanation like I was 5? :)
Sure.
The marching squares reconstructs the subpixel edge (blue) from the surrounding 2x2 pixels (red):

This way the distance (orange) to the edge is much more precise; in contrast to using whole pixel positions only where the distance between two neighbouring pixels can naturally be only 1 or sqrt(2).
The only way to get a reasonable precision without subpixel-precision is to increase the resolution but that makes it extremely slow.

Another question regarding the shader that would be used to draw these distance field fonts.  It would look up a texel, and it would know how far from the font it is by this lookup.... but what to do with that info?  Do I draw here or not?
When fetching a texel from the distance-map a value >=192 is "inside" the character and <192 is "outside".
So in the easiest case you can just enable alpha-testing and drop all outside texels (that's compeltely un-antialiased, though).
Inside a shader you could do all sorts of color-ramping near the boundary to simulate anti-aliasing, glow, shadows, etc.

At the moment I'm not quite sure if the threshold of 192 makes much sense.
I just figured that font-characters are usually rather thin and there's probably more information outside than inside...

edit: the threshold value changed from 192 to 128 in the current version.
« Last Edit: April 21, 2012 by hellfire »
Challenge Trophies Won:

Offline Voltage

  • Professor
  • Pentium
  • *****
  • Posts: 857
  • Karma: 53
    • View Profile
Re: Bitmap-Font Maker
« Reply #25 on: April 18, 2012 »
After reading that a couple (read 4) times, it clicked. \o/

So, for each pixel in char block, get distance from this pixel centre to the calculated subpixel surface.  Adjust and clamp tween 0 and 1, and store. Right?

Thanks for the explanation hellfire.

Regarding all this effort though, couldn't you just blur the original 2 bit texture and use that?  I'll attempt to answer that myself.
Challenge Trophies Won:

Offline Voltage

  • Professor
  • Pentium
  • *****
  • Posts: 857
  • Karma: 53
    • View Profile
Re: Bitmap-Font Maker
« Reply #26 on: April 18, 2012 »
heh. Cause blur and distance are different functions.  Distance affects the surrounding pixels but leaves the original font pixels untouched.  Blur doesn't.

As you were people.
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Bitmap-Font Maker
« Reply #27 on: April 18, 2012 »
get distance from this pixel centre to the calculated subpixel surface.  Adjust and clamp tween 0 and 1, and store. Right?
Pretty much, yes. The distance of an outside pixel is positive and the distance of an inside pixel is negative.
That's mapped to 0..255 where 128 represents a distance of 0.0, so it's right on the edge.

Quote
couldn't you just blur the original 2 bit texture and use that?
Yeah, when looking at the output of the distance-transform it just looks kinda blurred and actually it's not such a bad approximation.
It doesn't preserve hard corners, though - everything gets soft and round.
And, as you already noticed, it affects the threshold to the interior part.

« Last Edit: May 26, 2012 by hellfire »
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Bitmap-Font Maker
« Reply #28 on: April 20, 2012 »
Fixed a bug in the distance calculation, another one in the character positioning and moved the interior threshold to 128 (0.5) because it's nicer to handle.
Link (in post #1) updated.
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2756
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Bitmap-Font Maker
« Reply #29 on: April 20, 2012 »
Nice!
I'm going to test it later.
Challenge Trophies Won: