Only the lowest level of support - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Only the lowest level of support (/thread-8193.html)
Only the lowest level of support - Miglu - Oct 11, 2010 01:19 PM
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?
RE: Only the lowest level of support - Oddity007 - Oct 11, 2010 01:48 PM
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.
RE: Only the lowest level of support - AnotherJake - Oct 11, 2010 03:32 PM
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.
RE: Only the lowest level of support - Miglu - Oct 12, 2010 08:42 AM
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?
RE: Only the lowest level of support - OneSadCookie - Oct 12, 2010 08:59 AM
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.
RE: Only the lowest level of support - AnotherJake - Oct 12, 2010 10:06 AM
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.
RE: Only the lowest level of support - Oddity007 - Oct 12, 2010 01:07 PM
(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)
RE: Only the lowest level of support - Miglu - Oct 12, 2010 01:14 PM
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.
RE: Only the lowest level of support - AnotherJake - Oct 12, 2010 03:07 PM
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.
RE: Only the lowest level of support - Miglu - Oct 13, 2010 09:27 AM
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.
RE: Only the lowest level of support - AnotherJake - Oct 13, 2010 09:39 AM
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.
RE: Only the lowest level of support - OneSadCookie - Oct 13, 2010 10:03 AM
RE: Only the lowest level of support - Miglu - Oct 15, 2010 09:25 AM
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?
RE: Only the lowest level of support - OneSadCookie - Oct 15, 2010 09:45 AM
Look at the demo code.
RE: Only the lowest level of support - Miglu - Oct 15, 2010 11:01 AM
Do you mean http://onesadcookie.com/svn/NSViewTexture/NSViewTextureTest.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.