Question

Does anyone know how can i render a string on the iphone? Its for displaying my frame per second with =p

Was it helpful?

Solution

There's no built-in way of rendering text in OpenGL but two more or less common techniques: Rendering the glyphs using geometry (less common) or using texture mapping (far more common). For your case texture mapping would be very easy: Set up a CGBitmapContext and render the text using Quartz. Then upload the image in the previously generated texture using glTexSubImage2D.

On the iPhone you could also just put a UILabel on top of you OpenGL view and let UIKit do the rendering. In my application this did not hit performance at all (even though Apple claims it does).

OTHER TIPS

You can use a Texture2D and the initWithString method to draw text in OpenGL. See the crash landing example that is included in the iphone sdk.

You could also use a UILabel and have it on top of the opengl layer.

As said before, Texture2D is a good idea, but Crash Landing was removed from a lot of places in Apple, what you could do , is download the Cocos2d , and then extract the Texture2D class provided there ( it's the same class provided by Apple, but with a couple of more things ) Cocos 2D for iPhone

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top