OpenGL-ES Font Rendering (on iOS)… Sanity Check

血红的双手。 提交于 2019-12-10 09:45:56

问题


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?


回答1:


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.




回答2:


Here is a good texture mapped tutorial I used. Obviously this uses display lists and stuff that you can't do in OpenGL ES however it should not be too difficult to convert over. You can also look at some different techniques here. One technique draws each character with faces.



来源:https://stackoverflow.com/questions/3692641/opengl-es-font-rendering-on-ios-sanity-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!