Michaelangel007 / freetype-gl

Automatically exported from code.google.com/p/freetype-gl
Other
0 stars 0 forks source link

A new demo for distance transform #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
working base: r119

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

Original issue reported on code.google.com by wangyong...@gmail.com on 7 Mar 2012 at 4:49

GoogleCodeExporter commented 9 years ago
Here is the demo.

Original comment by wangyong...@gmail.com on 7 Mar 2012 at 4:52

Attachments:

GoogleCodeExporter commented 9 years ago

Why do you want to generate high resolution bitmap glyph to get distance field 
before down sampling ? The final quality depends on the actual size in the 
texture atlas and the distance field would be far more faster to compute on 
such "small" glyphs, no ? Another technics would be to generate distance field 
inplace each time you add a glyph int the texture atlas.

Anyway, I don't think that making this (genetating distance field) the default 
behavior is a good idea since the rendering quality is not the same, especially 
for small sizes.

Nicolas

Original comment by Nicolas.Rougier@gmail.com on 7 Mar 2012 at 12:17

GoogleCodeExporter commented 9 years ago
>> Why do you want to generate high resolution bitmap glyph to get distance 
field before down sampling ?

Because the quality of distance field is depend on the resolution of original 
bitmap. Especialy for characters that with complicate stroke, e.g. "聪", with 
small bitmap strokes would mix together. 

>>  Another technics would be to generate distance field inplace each time you 
add a glyph int the texture atlas.

Yes. But distance field bitmap always larger than the original one. How to 
compute the actual size that it will take?

>> the rendering quality is not the same, especially for small sizes

Yes. It's a trade between quality and cost. The bigger the font point size, the 
more texture you must consume. With distance field, you just need a constant 
point size and could scale it much bigger with acceptable quality. 

Original comment by wangyong...@gmail.com on 8 Mar 2012 at 1:25

GoogleCodeExporter commented 9 years ago
here is the compare of edt glyph (left) and freetype glyph (right)

http://i279.photobucket.com/albums/kk132/greatsorcerer/edt.png

Original comment by wangyong...@gmail.com on 8 Mar 2012 at 1:35

GoogleCodeExporter commented 9 years ago
I think the distance field is not larger than the original glyph because it 
goes from outside to the inside. In the distance field demo, I just pack glyphs 
as usual and then compute the distance field. Results seem correct to me.

And 1024x1024 is definitely too large for computing the distance field for a 
single glyph.

Original comment by Nicolas.Rougier@gmail.com on 8 Mar 2012 at 8:28

GoogleCodeExporter commented 9 years ago
On the screenshot, at what size did you generate the distance field ?

If you don't mind,  I will close this issuer since it might be better to talk 
about that in the freetype-gl users group.

Original comment by Nicolas.Rougier@gmail.com on 8 Mar 2012 at 8:31

GoogleCodeExporter commented 9 years ago
On the screenshot, at what size did you generate the distance field ?

If you don't mind,  I will close this issuer since it might be better to talk 
about that in the freetype-gl users group.

Original comment by Nicolas.Rougier@gmail.com on 8 Mar 2012 at 8:31

GoogleCodeExporter commented 9 years ago
>> On the screenshot, at what size did you generate the distance field ?

1024x1024, then scale to 32x32

>> If you don't mind,  I will close this issuer since it might be better to 
talk about that in the freetype-gl users group.

It's OK. BTW, how can I join the freetype-gl users group ? 

Original comment by wangyong...@gmail.com on 9 Mar 2012 at 12:57

GoogleCodeExporter commented 9 years ago
The address is: https://groups.google.com/forum/?fromgroups#!forum/freetype-gl

Either post and I will allow you forever or register (it's somewhere on the 
page)

Original comment by Nicolas.Rougier@gmail.com on 9 Mar 2012 at 7:20