简体   繁体   English

OpenGL 上基于矢量的字体

[英]Vector-based fonts on OpenGL

I started working at this company that uses an 2D OpenGL implementation to show our system's data (which runs on Windows.) The whole system was built with C++ (using C++Builder 2007).我开始在这家公司工作,该公司使用 2D OpenGL 实现来显示我们系统的数据(在 Windows 上运行)。整个系统是用 C++ 构建的(使用 C++Builder 2007)。 Thing is, all the text they print there are pixelized when you zoom in, which I think happens because the text is a bitmap:事实是,当您放大时,他们在那里打印的所有文本都已像素化,我认为这是因为文本是位图:

视图示例

From what I know they use the same font files as Windows does.据我所知,他们使用与 Windows 相同的字体文件。 I asked around here on why this happens and the answer I got is that the guy who implemented it (which doesn't work at the company anymore) said fonts on OpenGL are hard and this was the best he could do or something like it.我问这里为什么会发生这种情况,我得到的答案是实现它的人(不再在公司工作)说 OpenGL 上的字体很难,这是他能做的最好的事情或类似的事情。

My question is: is there any simple and effective way to make the text also a vector (the same way those lines in the picture are?) So when I zoom the camera, which happens a lot, they don't pixelize.我的问题是:是否有任何简单有效的方法可以使文本也成为矢量(就像图片中的线条一样?)所以当我缩放相机时,这种情况经常发生,它们不会像素化。 I have little knowledge of OpenGL and if you have some guide and/or tutorial related to this to point me towards the right direction I'd be very thankful.我对 OpenGL 知之甚少,如果您有一些与此相关的指南和/或教程来为我指明正确的方向,我将不胜感激。 Basically any material would be great.基本上任何材料都会很棒。

Most of OpenGL text rendering libraries come to this :creating bitmaps for the fonts, which means you are going to have problems with scaling and aliasing unless you do some hacks.One of the popular hacks is Valve's approach .You use signed distance field algo to generate your fonts bitmap which is then helps you to smooth the text outlines on scale during rendering.大多数 OpenGL 文本渲染库都这样:为字体创建位图,这意味着除非您进行一些黑客攻击,否则您将遇到缩放和锯齿问题。流行的黑客攻击之一是 Valve 的方法。您使用符号距离场算法来生成您的字体位图,然后帮助您在渲染过程中按比例平滑文本轮廓。 Here you can find the C++ implementation for Distance field generation .在这里您可以找到距离场生成的 C++ 实现。

If you stick to vendor specific hardware and that is NVidia ,you can try NVidia Path extension which allows to render graphics directly on GPU.如果您坚持使用供应商特定的硬件,即 NVidia,您可以尝试NVidia Path扩展,它允许直接在 GPU 上渲染图形。 Remember , it is NVidia only thing.请记住,这是 NVidia 唯一的东西。 But in general , signed distance field based approach is the smoothest and easiest to implement.但总的来说,基于符号距离场的方法是最平滑和最容易实现的。

Btw , freetype-gl uses Valve's approach and also the modern pipeline.顺便说一句, freetype-gl使用 Valve 的方法以及现代管道。

您可以尝试freetype-gl它是一个用于在 OpenGL 中进行字体渲染的库。

The issue with using fonts in OpenGL is that they are handled inconsistently across platforms, and that they have minimal support.在 OpenGL 中使用字体的问题在于它们跨平台的处理不一致,并且它们的支持很少。 If you're willing to go with a helper library for OpenGL ( SDL comes to mind), then this behaviour will likely be wrapped, meaning that you merely need to provide a suitable font file for them to use.如果您愿意使用 OpenGL 的帮助程序库(想到SDL ),那么此行为可能会被包装,这意味着您只需要提供合适的字体文件供他们使用。

你可以试试 FTOGL4 ,OpenGL4 的字体

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM