Distance fields

43 views
Skip to first unread message

Nicolas Rougier

unread,
Mar 8, 2012, 3:35:35 AM3/8/12
to freetype-gl

This is a follow-up from issue 15 (reported by wangyongcong) that is
more of a feature request than a real issue:

We could benefit much from euclidean distance transform, such as none-
cost scaling, easily outline / glow rendering... I'm trying to use edt
font in my game, the main idea is:
1, generate high resolution bitmap glyph (1024x1024 or bigger) with
Freetype
2, generate the distance transform of it
3, down sample the edt bitmap (scale to 32x32) and pack it into atlas
Then we could use it as normal glyphs.

Here is a simple demo (which is modified from demo-distance-field.c)
to demonstrate the idea. It print a line of text on the screen. You
could press +/- key to scale text size, and spacebar to show atlas.
The bigger the original font size, the better the scaled output.

It's an useful technique and could be part of texture_font_t : )

Notice: The program is only tested under VS. If you gat problems,
please email me

Behdad Esfahbod

unread,
Mar 8, 2012, 11:02:32 AM3/8/12
to freet...@googlegroups.com, Nicolas Rougier
On 03/08/2012 03:35 AM, Nicolas Rougier wrote:
> We could benefit much from euclidean distance transform, such as none-
> cost scaling, easily outline / glow rendering...

I thought SDF-sampling was what freetype-gl was doing already?

behdad

Nicolas Rougier

unread,
Mar 8, 2012, 12:13:57 PM3/8/12
to freetype-gl

This is not the default behavior, only one demo is provided to show
how to do it.

Nicolas

Nicolas Rougier

unread,
Mar 19, 2012, 3:58:37 AM3/19/12
to freet...@googlegroups.com

I added a new distance field demo to show how to use it with actual text (demo-distance-field-2).

Nicolas
Reply all
Reply to author
Forward
0 new messages