Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone OpenGl render text

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

like image 827
Cheng Lai Avatar asked Jul 27 '09 14:07

Cheng Lai


2 Answers

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).

like image 96
Nikolai Ruhe Avatar answered Oct 23 '22 15:10

Nikolai Ruhe


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.

like image 24
DHamrick Avatar answered Oct 23 '22 17:10

DHamrick