在 OpenGL ES 应用程序中加载 unicode 字体
我希望使用 freetype 库在我的 openGL ES 应用程序中加载 unicode 字体。我最初考虑使用 Arial Unicode MS,但它太大了,大约 24 MB。
还有其他更小的 unicode 字体吗?我还了解到其他一些 unicode 字体可能不够小,无法解决我的问题。有其他方法可以解决我的问题吗?
I wish to load a unicode font in my openGL ES app using freetype library. I initially considered using Arial Unicode MS, but it is too big, around 24 MB.
Is there any other unicode font available of smaller size? I also understand that some other unicode font might not be small enough to solve my problem. Is there any alternative approach to solve my issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你指的是纹理映射字体。正如您已经想到的,完整的 Unicode 字体会消耗相当多的空间。但是,更改字体不会产生影响,因为内存要求不取决于字体,而是取决于渲染到纹理图集的字形的分辨率乘以包含在集合中的字形数量。
虽然纹理映射字体对于只有有限数量字形(拉丁语、西里尔语、希腊语、韩语、阿拉伯语)的字母表来说是一个可行的选择,但如果您想支持完全国际化,它会变得相当笨拙。
有两个相当大的选项:
扫描要显示的文本以查找所需的所有字形,仅渲染和上传这些字形;这对于汉字和类似的大型脚本来说效果不太好。
使用 FreeType 和一些布局库(Pango 或类似)将整个文本渲染到缓冲区。
我建议使用 3 倍屏幕分辨率并使用灰度抗锯齿进行渲染。然后使用像素对齐的滤镜蒙版纹理进行调制,或使用片段着色器来实现子像素抗锯齿。
还有可能的第三种方法,但到目前为止我自己从未实现过:矢量纹理。本质上,您在片段着色器中实现抗锯齿样条线光栅器,并通过采样器提供样条线参数;这允许利用 GPU 加速渲染清晰的文本。
I think you're referring to texture mapped fonts. As you already figured, a full Unicode font consumes rather much space. However changing the font won't make a difference as the memory requirements don't depend on the typeface, but on the resolution the glyphs rendered to a texture atlas times the amount of glyphs that are included into the set.
While texture mapped fonts were a viable option for alphabets with only a limited number of glyphs (Latin, Cyrillic, Greek, Korean, Arabic) it gets rather clumsy if you want to support full internationalization.
There are two considerable options:
Scan the text to be displayed for all glyphs required, only render and upload those; this owever won't work so well for kanji and similar large scripts.
Render the whole text using FreeType and some layout library (Pango or similar) to a buffer.
I recommend rendering using 3 times the screen resolution using grayscale antialiasing. Then modulate with a pixel aligned filter mask texture, or using a fragment shader to implement sub-pixel antialiasing.
There is possible third method, but I never implemented it myself so far: Vector Textures. In essence you implement a antialiasing spline rasterizer in the fragment shader and supply spline parameters through samplers; this allows to render crisp text utilizing GPU acceleration.