Is there a decent OpenGL text drawing library for the iPhone SDK?

One way to do this is by setting up a UILabel and then rendering its layer into a texture. An indirect route to this would be to first set up the UILabel with text, font, etc. and then use the following code

UIGraphicsBeginImageContext(yourLabel.frame.size);
[yourLabel.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

to capture the UILabel to a UIImage. You could then use the initWithImage: constructor of the Texture2D class in the CrashLanding project to transform this to a texture.

It looks like initWithImage: in that example re-renders the UIImage to a bitmap context and uses that to create the texture. With a little work, you could extract the relevant code from that method and alter the above code to render your layer directly into the texture.

This way, you get the nice Unicode and font support of UILabel when creating the text for your texture.

Leave a Comment

tech