原文0 D4 ~$ m1 Q( O( ]* S7 H
http://www.gamedev.net/community/forums/topic.asp?topic_id=4919380 S6 o% Q, @( D% E% }& q! _) S
( k: v% Y O, d& I
用法1 N1 Z; R, @0 w
How to use:
! _- J. L6 V5 C: o: r! h* drag font files onto the exe. y+ N- R' b7 H0 W" V2 [& @# o& c; N- v
* the app asks for a texture size (256 will yield a 256x256 texture for each input font file)9 L* B' R6 l* b. v& O O
* the app will render all valid glyphs in the ANSI range [0..255]
6 O T8 }/ H& H; Z) `* the app will automatically search for the largest rendering size (integer pixels only, so hinting works with a greater range of TrueType fonts) where it can pack the output into the texture you specified earlier
: |6 o1 w2 o* Q4 K$ \+ W* the app packs the rendered Signed Distance Field glyphs into a single texture
8 N8 f' Y/ f9 C' E$ S# \7 W/ g* look at the output PNG and TXT file (in the same directory as the font file) ~+ r% S+ T$ a }$ B
7 T1 t8 N* {' d9 j% H( c
Credits:
) k- S" W7 R- U, z' ?7 b* E* FreeType2 for font rendering7 R; \' @/ i& m2 @* d1 c' e
* LodePNG for saving the resultant file# X# M+ i _) A9 j, M
* BinPacker code from GameDev's own jyk!: P% U3 j8 E3 u
w, w8 K, T! z/ u" b8 y6 mPlease try it out and let me know what you think. Here are my ideas for where I'm going after this (please give any feedback or feature requests):1 q* j) b! W7 v/ y$ D: P l' ~7 O( n
U5 x+ l7 v @- Q
* I want to output a text file compliant with AngelCode's BMFont spec so existing loaders can use this output without changing anything other than the alpha threshold
( k# p8 e' E& r
6 ?) n, A7 H+ B0 Y! e4 r* I want an XML file for configuration so you can specify specific unicode characters (I'm thinking <range>A B</range> and <chars>A B C...ZY ZZ</chars>)6 G* _$ t+ }" p
# a I3 q* I: [+ f! \& p2 y* I want to allow an image for input, where a Signed Distance Field would then be computed from that into a lower resolution texture
4 Y: a. g4 Z& Q1 p( T$ G: a4 W7 S% i" b" R0 p6 l
So, what do you think? The source will be released (MIT) when I'm a bit closer to done. (Note, the RGB and A channels all share the same signed distance data, so there is a bit of a border to each glyph...I could just use all white for the color, but I think this looks pretty good.)- v+ H% m$ U& W+ ~* H" W
0 i$ H& |3 Y4 W. e/ ~5 P, O+ X% T-----------------------------------------------------------------------------------------------------------2 V1 Z4 r* u# O) n+ \0 u) [) ~
I've updated the zip (same link). The changes:
- H( {- Q% O3 F8 V$ T- }$ q, A8 S3 r, \+ j
* after dragging fonts onto the exe, you specify texture size and the highest Unicode character number (only characters with glyphs will be rendered).
# D* g( L/ Z) p* V) t9 t1 B/ i; n! a, W3 n2 G
* the output text file now has the offset and advance information, so you can finally render text properly (I hope!) I appended "page=0 chnl=0" to the end of each line to mirror the AngelCode BMFont tool. Note that this info is not integer data, and the offsets may be negative (both functions of the same thing...the actual glyph has border texels to help define the Signed Distance Field)6 U* I# T; O. y. f
. D! G) v+ Q4 e0 u$ \* There is a bit more text describing the requested inputs
/ {6 ]; I7 |& |8 s. b0 B. @0 b& ^
8 i1 k" h3 ~3 c- [. d* there is much better error checking (e.g. dragging non-font files onto the exe)
$ E5 W' w' h# Q d
0 [$ ]/ d# j6 J8 J& }0 ?) L0 f9 ]* the zip now includes all my source code, ugly as it is (it also has the LodePNG and BinPacker code...you'll need to get and compile FreeType2 yourself)
& s h/ u: l8 S7 I# B
2 L7 B( K5 L. U6 \( a
+ I2 S# a/ k6 C" i@AndyPandyV2: thanks for the kind words, you're welcome for the app [8^)( f# n X$ S: C" o+ x# o1 `" C: d
( h& u" W8 A* p- m@OrangyTang & Kylotan: thanks for the feedback/input. As a simple hack you can now input the range of characters to be rendered. I think I like the XML approach as it would be slightly easier for me to implement than the UTF-8 file with all needed characters for 3 reasons: easier to parse as I already use an XML lib, I could see the UTF-8 file getting huge, and there is no guarantee of the glyph order after the packing (though the attendant text file would be in the specified order). Would the XML file be an OK solution for your needs? Or even the current incarnation? (note that rendering the entire Microsoft Arial font into a 4096x4096 took > 20 minutes, so I could see the use of limited sub-ranges! [8^)
1 \1 x$ I$ X4 I7 E
! f4 p3 w7 P' }6 a; ~8 }Here is some sample output, as I forgot to include this last time: |