原文
y7 ~ T: ]) N" T$ r2 p/ k' Bhttp://www.gamedev.net/community/forums/topic.asp?topic_id=4919381 ^5 v; b& H5 @ F9 \. }
9 t( t0 K/ x ?
用法
; C2 U& a# o# k% qHow to use:
i% }/ S/ Z( f' }" l5 A5 ]# ?; d* drag font files onto the exe% u5 q, c$ p ]% A% c& P! N$ y$ }
* the app asks for a texture size (256 will yield a 256x256 texture for each input font file)
4 Q& v2 [1 W1 e e* F* the app will render all valid glyphs in the ANSI range [0..255]
( [- u6 H$ O+ j* 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
+ D: p5 t$ C* z+ V* the app packs the rendered Signed Distance Field glyphs into a single texture" x( d ^8 W4 n0 t7 Z, X
* look at the output PNG and TXT file (in the same directory as the font file)
3 i. L/ l" Y& k8 q% I
3 ~/ h- u3 I6 A! e5 uCredits:
$ h% O' |1 g U4 |! e* FreeType2 for font rendering
2 u4 K" ~5 C; F* LodePNG for saving the resultant file
/ s; V$ f5 l. D$ Z& c: M5 r n% g* BinPacker code from GameDev's own jyk!
0 o ?- X: z. H! D- u" e9 {3 Q' \+ }7 \4 \7 W- Q x# z P
Please 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):
4 w0 K% l( ] F J ?0 W/ d3 C% Y# Y, x: l
* 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
8 \: i, ?5 w- S3 ~, e& _ O
4 I: H6 F1 Y* b: Q3 i" |6 M4 M( p* 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>)
% q- E+ ~& W1 c) {- ^+ w8 m, ]4 @; A$ M; v$ P
* I want to allow an image for input, where a Signed Distance Field would then be computed from that into a lower resolution texture. J9 a8 ?5 e2 [+ @) G7 Y3 ^
) {5 `7 D d! Z6 A: xSo, 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.)3 J1 Z& y, d. W& u
& C; X$ {6 Q" ]) f d: k6 Q
-----------------------------------------------------------------------------------------------------------
# p" j' y6 i: V0 ]- U! lI've updated the zip (same link). The changes:
7 s7 F/ r! z' v% d; B; x$ T- P u# q( x) ]6 s2 @
* after dragging fonts onto the exe, you specify texture size and the highest Unicode character number (only characters with glyphs will be rendered). f" O, J+ \6 [7 G
8 e6 T* y) m+ O2 }( ~4 V* 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)
5 q. M" `9 j, s0 j. @4 I2 v- |) K4 z5 h: W5 i4 ^" H
* There is a bit more text describing the requested inputs
8 o1 X" n# w+ g: Z' g$ X' `2 K& Z7 Y' z; w8 o6 l( m
* there is much better error checking (e.g. dragging non-font files onto the exe)& h) ?8 r# c/ i: a4 r. e$ k) L: Q
8 w, `. j$ }: x# e% u- |
* 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), n; d( z# a. K2 i; o' ~
2 v( R" J( d$ l" S3 W
" L8 U, q. f% ]; D
@AndyPandyV2: thanks for the kind words, you're welcome for the app [8^)
/ E/ D; j9 n9 x Q2 w6 Y$ ~4 |" d Y; ?* J, h
@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^)6 S1 v) u2 A) }" i3 w" ]4 n1 y
& S; K6 T# F4 P7 {
Here is some sample output, as I forgot to include this last time: |