Banyak orang tahu masalah grafis tiga dimensi - kurangnya solusi lintas platform ringan dalam masalah output teks.
Sebagian besar implementasi memungkinkan Anda untuk menggunakan font yang dipilih sebagai tekstur. Pustaka ttf2mesh yang diterbitkan mengimplementasikan cara lain - ia mengubah karakter vektor font TrueType ke objek kisi. Ini memungkinkan Anda untuk menampilkan teks sebagai seperangkat segitiga.
![gambar](https://habrastorage.org/webt/ge/o4/q0/geo4q0i6y-ue6hqpbw7gcflnww8.gif)
Pendekatan ini memiliki kelebihan dan kekurangan penting. Kompleksitas tugas yang dijelaskan di bawah ini dan kontemplasi bentuk-bentuk desain font yang luar biasa membawa banyak kesenangan dalam pengembangan. Saya harap Anda menikmatinya juga.
Perendaman dalam masalah
Di situs web stackoverflow, Anda dapat menemukan pertanyaan "Bagaimana cara menggambar teks menggunakan metode OpenGL saja?" . Jawaban terperinci untuk itu dimulai dengan frasa "Mengapa itu sulit". Saya akan memberikan terjemahan singkat dari jawaban ini, karena lebih baik - hampir tidak mungkin untuk menggambarkan masalahnya.
Font umum (seperti TrueType atau OpenType) memiliki format vektor untuk mewakili karakter: garis besarnya ditentukan oleh seperangkat kurva Bezier.
![gambar](https://habrastorage.org/webt/qx/ro/xy/qxroxy7jked2j4ivzpcfknwgrgw.gif)
β OpenGL, (, , ).
, CPU, β OpenGL- . , . :
![gambar](https://habrastorage.org/webt/qf/vf/jt/qfvfjts8pohy8hddpvwfhgs0yq4.png)
, . , web- (CSS-sprites).
FOSDEM 2014, , :
- : . GPU . : ; O(N log N).
- . : , . Resolution independent cubic bezier drawing on GPU (Blinn/Loop)
- OpenVG. : API , (. OpenGL, OpenVG. Draw text OpenVG implementation)
, 3d- 2016 . .. "Distance fields" ( , . ). .
FreeType
FreeType . FTGL, API, "Distance fields" .
β libgdx.
github.com/nothings/stb/blob/master/stb_truetype.h
www.angelcode.com/products/bmfont
, . (DDS, PNG) . β .
FOSDEM 2014 .
: β ? 6000 ( Ubuntu ):
![gambar](https://habrastorage.org/webt/ln/a0/es/lna0eslnfqzmyjfi-gqfeo5dnza.jpeg)
2.5 (Times New Roman , 15000 ).
, , ( )? ( , , , GPU ), .
O(N log N)
, , . , ( ) β . log(N) . , . , , .. " " , , . , .
, . , :
: ; .
. "" "", .
ttf2mesh
" ". ttf2mesh β (ttf2mesh.h ttf2mesh.c) C99. , :
API. , ttf2mesh.h doxygen-. ttf_export_to_obj, Wavefront .obj. , . examples - ttf2obj.
:
- TTF- ,
- ( )
5.1.
5.2. ( )
5.3.
5.4.
TTF-
Microsoft (OpenType specification). OpenType- (.otf) β TrueType- (.ttf), , . , , TTF, , OTF TTC.
. ( ELF ) TrueType β¦ . β¦ , , .
TTF- Windows 7 font list Ubuntu 18.04.4 LTS ( 500 TTF ).
TrueType β . .
β , . outline quality .
![gambar](https://habrastorage.org/webt/-2/pd/x6/-2pdx6a15jrfgfpb0tamf3lw_8s.gif)
.
ttf2mesh . TTF_QUALITY_LOW, TTF_QUALITY_NORMAL TTF_QUALITY_HIGH. . .
![gambar](https://habrastorage.org/webt/lx/cz/d1/lxczd1bnzbixx88grh1abzethsc.png)
"Q" 76, 97 175 .
, . β . . , . . :
, , U+2592 (β). . , , Ctrl+V. β¦ : , .
, ( ), EPSILON.
β .
. , . , - , . . ?
β .
Microsoft Apple. . , Microsoft Apple (. Overlapping contours) .
, ( , ?). β , . , even-odd , nonzero.
, 0.1% Windows 7. 497931 680 UNICODE:
UNICODEBasic Latin β 14 errors
Latin-1 Supplement β 9 errors
Latin Extended-A β 2 errors
Greek and Coptic β 2 errors
Thai β 11 errors
Letterlike Symbols β 1 errors
Mathematical Operators β 1 errors
Block Elements β 1 errors
Geometric Shapes β 1 errors
Hiragana β 1 errors
Enclosed CJK Letters and Months β 1 errors
CJK Unified Ideographs Extension A β 74 errors
CJK Unified Ideographs β 555 errors
Private Use Area β 3 errors
CJK Compatibility Ideographs β 4 errors
, 36 497931 ( 0.01%). "Basic Latin", : IrisUPC, KodchiangUPC, LilyUPC, Footlight MT Light, Kunstler Script, Papyrus, Parchment Viner Hand ITC. UPC (Unity Progress Company).
, . , .
. "B", , 3 : - . "" 1 -. - . .
![gambar](https://habrastorage.org/webt/rm/iq/hi/rmiqhijenjscfvpp8wejvkz8zkg.gif)
, , . U+00A2 β (), , ().
)
) ![gambar](https://habrastorage.org/webt/tm/jw/6l/tmjw6lff6czkwo_iyfol6ea3ruk.png)
. β , . β¦ . , . β "/" "C". . β , - "" .
, , . . . .
![gambar](https://habrastorage.org/webt/uz/ib/ti/uzibtidh0j7x7o9huunwscj7cbe.gif)
1) (y). p19, p15 .
2) . . , advancing front, . . .
3) , , 2 . , .
4) .3 , . p2.
5) . , . p5.
( Point event) , 2008 V. Domiter & B. Ε½alik "Sweepβline algorithm for constrained Delaunay triangulation" (DOI: 10.1080/13658810701492241).
( ) , . , , . .
. , .
![gambar](https://habrastorage.org/webt/lb/o9/by/lbo9byxer_n3oxfnb3xdgu7sone.png)
( X β , Y β ).
, , ( ) O(N). , O(N log N) , , . .
, , 2000 . "Tibetan Machine Uni" U+0FC7 (Tibetan Symbol Rdo Rje Rgya Gram) :
:
![gambar](https://habrastorage.org/webt/zf/to/qh/zftoqhtdhqjjaeixcxn6mjm7tcs.png)
OpenGL MSAA:
![gambar](https://habrastorage.org/webt/oo/nb/1x/oonb1xsstkepba8xymwjgjyoavq.png)
...
. ( , , ) . , . .
ttf2mesh , . OBJ . , SVG , , PostScript.
. β , .
![gambar](https://habrastorage.org/webt/-z/60/mj/-z60mj6volo0p5unfcuu8fb1gtk.gif)
Pustaka ttf2mesh memiliki lisensi MIT dan tersedia di sini . Saya berharap ini akan bermanfaat secara sosial.