Only the lowest level of support

This is from the Red Book: "OpenGL provides only the lowest level of support for drawing strings of characters and manipulating fonts". So which one should be used to draw strings into an OpenGL view: OpenGL or Core Graphics?

Use OpenGL, create a texture atlas with the font glyphs in and render it as you would a sprite. You could potentially use Core Graphics to create the font texture atlas. I'm not sure why the redbook even mentions OpenGL having any support for fonts, and it gets even worse when online code references some custom glDrawText() or similar, confusing people who believe that it's actually an opengl function.

My guess is they only mention it because of the basic (and slow) string support in GLUT, which is part of the "GL family" I suppose, although it's not part of the spec.

Instead of an atlas, you can use Core Graphics to render a string to a single texture, which even includes typesetting. You can find an example of that in the famous Texture2D class.

You can also use FreeType for rendering text to a texture, but you have to do your own typesetting. This is what I do for generally static text if I'm not using special effects for the text. For stuff that changes often, I do the single-character-per-quad approach.

Whether you're programming for the Mac or the iPhone, rendering text without touching ObjC will be at best harder than necessary and at worst actually impossible. You need to know the basics of ObjC to code for either platform. Learn it.

I'll have to agree with OSC. To use Texture2D requires very little amounts of Obj-C (maybe as little as three lines of it, to create the texture, grab the GL name, then dealloc it when finished using it), which shouldn't take more than an hour to pick up.

If you absolutely want all C then you can use FreeType, but that will take significantly more work than simply learning a tiny bit of Obj-C for Texture2D. Plus if you're doing it for iPhone, you'll have to learn to compile the library for iPhone which is definitely doable, but I found it to be a bit tricky.

The alternative is the good ol' bitmap font texture as Oddity007 already suggested, where you have one character per quad. If you just want quick and easy text with no special effects though, Texture2D is the way to go for iPhone IMHO, since it is so ridiculously simple to use.

(Oct 12, 2010 08:42 AM)Miglu Wrote: I could not find any C examples of Texture2D. This is not C.

For one, it's the wrong thing entirely. Two, the one you want seems to be mysteriously absent from the internet. (That, or it's hidden away in Apple's developer page and isn't being archived by google)

Texture2D uses UIKit, so it is not useful for Mac programming. It seems that if I do not want to convert it to normal Cocoa, I have to use a bitmap font texture, like was suggested. It is annoying that no-one has released a Mac version of Texture2D even though most Mac games are done with OpenGL and have font. So every guy has to make his own font drawing method.

You'll need some adjustments to make a version of Texture2D work on Mac, but it's possible. Even easier for Mac you can use OneSadCookie's little thingamabobber for it. I don't remember the link, but I'm sure he does.

You're probably going to want to learn to do the bitmap font technique anyway as well.

When using NSViewTexture, is ConvenienceCreateNSTextView all that is needed to create the view so that the string is displayed until the view is deallocated? To prevent "No." answers: if not, what else is needed?