开发者

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

开发者 https://www.devze.com 2023-01-15 13:58 出处:网络
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 开发者_开发技

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:

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

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消