光栅化 Java 字体
说明:
我正在通过 JOGL 用 Java 编写一个 OpenGL 应用程序。 GLUT 的内置字体非常基本。我希望能够采用 Java 字体,将其中的所有字符渲染为 2D 字节数组(表示字符的灰度图像),然后我可以将其作为纹理加载到 OpenGL 中。
问题:
我可以在 OpenGL 中加载纹理;我可以使用 JOGL。我唯一的问题是从“Font java cn read”--> “所有角色步骤的二维灰度图像”。我应该使用哪些函数/库?
Exposition:
I'm writting an OpenGL app in Java via JOGL. The built in fonts with GLUT are very basic. I want to be able to take a Java Font, render all the characters in it to a 2D array of bytes (a greyscale image representing the characters), which I can then load as a texture in OpenGL.
Problem:
I can load the textures in OpenGL; I can use JOGL. My only problem is going from the "Font java cn read" --> "2D greyscale image of all the characters step". What functions / libraries should I be using?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
处理可以在 OpenGL 中渲染字体,并且它使用自己的内部开源类 PFont 来“为字体中的每个字形生成给定大小的灰度位图图像”,正如 Kevin 所说。我建议您查看源代码, 在这里。
Processing can render fonts in OpenGL, and it uses it's own in house open source class PFont to "generate grayscale bitmap images of a given size for every glyph in a font," as Kevin put it. I recommend you look at the source, which is here.
我不确定我是否完全理解您在寻找什么。我认为您想要的是一些代码,可以为字体中的每个字形生成给定大小的灰度位图图像。
没有办法(无论如何我都知道)来获取字体支持的所有字形(奇怪的是,你可以获得字形的数量......所以是的,我可能只是错过了一些东西,呸)。但是,您可以非常轻松地获取给定字符的字形度量。
这些方面的东西应该对你有用。
请注意,我在某些地方进行了裁剪而不是四舍五入,这可能是一个问题。
I'm not sure I quite understand what you're looking for. I think what you want is some code that will generate grayscale bitmap images of a given size for every glyph in a font.
There isn't a way (that I am aware of anyway) to get all the glyphs a font supports (oddly, you can get the number of glyphs... so yeah, I may just be missing something, bah). However, you can get glyph metrics for given characters quite easily.
Something along these lines should work for you.
Note that I'm clipping rather than rounding in some places, which could potentially be an issue.
可能我遗漏了一些东西,但是 java.awt 不能为你做大部分事情吗?
Possible I'm missing something, but can java.awt not do most of this for you?