views:

1743

answers:

3

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

+3  A: 

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

Nikolai Ruhe
how do i layer the UILabel on top of the openGL view?
DrkZeraga
Just add it as a subview: `[myGLView addSubview:myUILabel];`
Nikolai Ruhe
AAAAAH!! A widget on top of your subview/??
bobobobo
+3  A: 

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.

DHamrick
do u know where can i get the font needed?
DrkZeraga
nvm lol i found the list of font names on google =p
DrkZeraga
+2  A: 

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

Mr.Gando