问题描述
我正在为iOS编写游戏。它有一个游戏地图,我用OpenGL来绘制它,因为其他选项太慢了。我在地图上有单位,用字母表示,是一个la矮人堡垒(lawar href =http://www.bay12games.com/dwarves/\" rel=\"nofollow noreferrer\">矮人要塞)。但是,在OpenGL中渲染文本。目前我正在使用一个性能调整的Texture2D突变体,这个突变体足够原型,但是存在各种各样的问题,而且没有产生漂亮的结果我看来,这样做的尝试和真正的方法是生成一个目录的图像文件的所有字母呈现在一个字体,然后当你想渲染它们时,将这些贴图贴图到纹理上(参见)。不过,我在地图上放大缩小了很多。加上视网膜显示加上iPad将需要多个分辨率。丑陋。
想一想有更好的办法,我查了一下,它可以在iOS / OpenGLES上动态呈现TTF / OTF字体。这不是即插即用的。我已经摔了两天,甚至接近工作,但我认为我现在已经走上了黄金道路。所以...我疯了吗?我为自己创造了更多的工作方式吗?
是的,这太疯狂了,为自己创造了更多的工作。对于我的具体情况,Texture2D几乎囊括了我所需要的所有秘密。我决定接受Texture2D的所有权,学习它,并把它做成我自己的。通过渲染一个更大的字体(50分)然后缩小,我在OpenGL中得到了非常好的结果: b
I'm writing a game for iOS. It has a game map, and I'm using OpenGL to draw it, because the other options were too slow. I have units on the map, represented by alphabetic letters, a la Dwarf Fortress. However, rendering text in OpenGL bites.
I'm presently using a performance-tweaked mutant of Texture2D, which was good enough to prototype, but that has all kinds of problems, and is not producing pretty results for me.
It seems that the tried-and-true way to do this is to generate a "catalog" image file with all the letters rendered in a font, and then map these on a texture when you want to render them (cf. here). However, I'm zooming in and out a lot on my map. That plus Retina Display plus iPad will require multiple resolutions. Ugly.
Thinking there must be a better way, I checked out FTGLES, which can dynamically render TTF/OTF fonts on iOS/OpenGLES. It's not plug and play. I've wrestled for a couple of days to get it even close to working, but I think I've got the golden path now. So... am I crazy? Am I creating way more work than I should for myself?
Yes, this was crazy, and creating more work for myself. For my specific case, Texture2D held almost all the secrets I needed within. I decided to take ownership of the Texture2D, learn it, and make it my own. By rendering in a bigger font (50 points) and then scaling down, I get really good results in OpenGL:
Note that I was already optimizing by creating one Texture2D object per letter and then looking these up when I needed them. I can further optimize by collecting all my texture draws and making one OpenGL draw call per color.
这篇关于OpenGL-ES字体呈现(在iOS上)...合理性检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!