Only the lowest level of support

Member
Posts: 131
Joined: 2010.08
Post: #1
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?
Quote this message in a reply
Member
Posts: 227
Joined: 2008.08
Post: #2
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.
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #3
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.
Quote this message in a reply
Member
Posts: 131
Joined: 2010.08
Post: #4
I could not find any C examples of Texture2D. This is not C. Could you give a tutorial about using Core Graphics to render a string to a single texture?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
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.
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #6
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.
Quote this message in a reply
Member
Posts: 227
Joined: 2008.08
Post: #7
(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)
Quote this message in a reply
Member
Posts: 131
Joined: 2010.08
Post: #8
Thanks. By "C" I meant Objective-C and Cocoa as well as C, as they are built with it. Is it right to refer to them as C? They are like subclasses: however much is added, they are still the superclass.
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #9
How funny, I didn't even notice the link. Yeah, that ain't the right one.

It's not good to refer to Objective-C as C, since as you can tell by this thread, you confused OSC and I.

Try googling:

texture2d filetype:m
Quote this message in a reply
Member
Posts: 131
Joined: 2010.08
Post: #10
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.
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #11
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. Wink

You're probably going to want to learn to do the bitmap font technique anyway as well.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #12
Quote this message in a reply
Member
Posts: 131
Joined: 2010.08
Post: #13
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #14
Look at the demo code.
Quote this message in a reply
Member
Posts: 131
Joined: 2010.08
Post: #15
Do you mean http://onesadcookie.com/svn/NSViewTextur...reTest.cpp? So that I have to add TexImageNSView()? The text is still not drawn. Sorry for asking so many questions. I ask them as I am a beginner at C, Objective-C and Cocoa.
Quote this message in a reply
Post Reply