OpenGL ES rendering dynamic text?

Any tutorials/ideas on how to render dynamic text in OpenGL ES? For example, displaying a users score, etc.

Thanks

Macbook Pro, Mac OS X (10.5.4), no

Posted on Aug 3, 2008 8:38 PM

Reply
10 replies

Aug 20, 2008 3:32 PM in response to Squimmy

Last time I did this in OGL, I just rolled my own bitmap font, and rendered the score manually. You just need 10 bitmaps that you stick in a texture, and then render 1 quad per number in the score.

You could try creating a UIView on top of your glview, inserting a UITextLabel in that and making those transparent, but I have no idea if that works on top of a GL view.

Aug 20, 2008 3:33 PM in response to Squimmy

I made an OpenGL ES game with dynamic text. I asked a similar question and people pointed me towards the Texture2D class in the Apple CrashLanding sample. But, I found this a little too slow for my needs.

So what I did, which is what you may not want to hear, is loaded a texture into my game which had "0-9" and "a-z" just like any other OpenGL texture. Then indexed it with specific texture coordinates for each alphanumeric.

Sep 5, 2008 11:30 PM in response to iphonemrdev

The "CrashLanding" tutorial for the iPhone comes with an example of how to do this. It becomes two lines of code once you download the example.

But basically, you download "CrashLanding" from the iPhone SDK examples, and you copy the "Texture2D.h" and "Texture2D.m" files.

Then you just call "initWithString." You can even choose a specific font and font size.

Note that making a new Texture2D is fairly slow, so you probably only want to regenerate the texture when it changes, and not 60 frames per second.

Sep 5, 2008 11:32 PM in response to Macmenace

You won't have as much control, and it will be slower, but if you don't update the texture every single frame (i.e., you only update it when the text actually changes), then the example in Texture2d.h/m in "CrashLanding" is going to be much easier than rolling your own text system.

Rolling your own will give you more control. You will have to figure out character spacing and stuff yourself, though, so for a non-monospaced font it is probably not worth it.

Sep 8, 2008 9:46 PM in response to iphonemrdev

There's a good overview of fonts in OpenGL here:
http://www.opengl.org/resources/faq/technical/fonts.htm

Most games tend to use the textured font techniques, which unfortunantly aren't straightforward for beginners to understand. Often, the most difficult part is generating a good base texture to "snip" your glyphs from. This looks like a good tool to try: http://www.pixelperceptions.com/

By learning about this you'll cover basic stuff like texture mapping & blending, which you will need to know anyway if you're interested in OpenGL or games programming. There's good tutorials for texturing and blending all over the place.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

OpenGL ES rendering dynamic text?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.