fast text with cocoa?

Member
Posts: 194
Joined: 2009.02
Post: #1
I'm working on a game in C (with the system stuff in cocoa) and I need a quick way to draw text into the opengl view game window from within my C code. I looked into graphic texture fonts but making them proportional seemed liked way too much trouble. So what would be the best way to go?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #3
Thanks osc for the code, that's exactly what i've been searching for. I ran across a nehe tutorial which seemed very similar to yours and would be curious to know what you think of it, and if one has any advantages over the other.

http://nehe.gamedev.net/data/lessons/les...?lesson=13

Also, is there some way to forcibly install a font into the users computer along with your game?
Quote this message in a reply
Sage
Posts: 1,234
Joined: 2002.10
Post: #4
Put the font in your app bundle. See ATSApplicationFontsPath.
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #5
Thanks for the info arekkusu, but I am a bit perplexed by the ATSApplicationFontsPath string. As far as I understand, I should go into info.plist and write:

"ATSApplicationFontsPath" = "/fonts" if I had a folder in my bundle's resource folder called "fonts" with the relevant fonts themselves
also tried ATSApplicationFontsPath = "/fonts"

...and "ATSApplicationFontsPath" = "/fonts/font_name"
....and "ATSApplicationFontsPath" = "fonts/"
....and "ATSApplicationFontsPath" = "/fonts/font_name.ttf

...and just about every other possible varient I could imagine, none of which worked.

The actual font file is a .ttf, if it matters. I think I'm overlooking something obvious.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
it should definitely not begin with a /. If you have MyGreatApp.app/Contents/Resources/Fonts/MyGreatFont.ttf, you can use either "Fonts" or "Fonts/MyGreatFont.ttf". If you're using Xcode to build your app, chances are that you *don't* have a subfolder of Resources, 'cos that's excessively difficult to do in Xcode, so chances are you just want "MyGreatFont.ttf". Either way, look in your built application to find out exactly where the font is.
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #7
Okay, I threw out the intermediate "Fonts" folder and now the actual path(not the one I pass ATSApplicationFontsPath) to myFont.ttf looks like this:

myApp.app/Contents/Resources/myFont.ttf

My understanding is that whatever path you assign to the string ATSApplicationFontsPath is appended to the path myApp.app/Contents/Resources so that if my font is in resources I would just pass it "myFont.ttf", but if I wanted to specifiy Resources as the directory(meaning I wanted to include all fonts within the resource folder)would I use "" as the path, or something different?

While I understand that you can use ATSApplicationFontsPath to specify either a directory of fonts, or a single font, I'm still unable to get it working.

How should my InfoPlist.strings look, like this...

ATSApplicationFontsPat = "myFont.ttf";

... or like this...

ATSApplicationFontsPath" = "myFont.ttf";

I tried both and neither work. I also tried googling ATSApplicationFontsPath but was unable to find any actual source code examples, only documentation on how it works(which I think at this point I pretty much understand), might anyone have any actual source code using ATSApplicationFontsPath?.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
not InfoPlist.strings, Info.plist. In Xcode there's a special dialog somewhere to edit it, but you can probably just edit the file directly too.
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #9
Yeah, I actually meant to say info.plist, not info.plist strings. So I did exactly that using the info.plist editor, and then checked the info.plist file itself to confirm that it was correct, and it still hasn't worked.

In property list editor I set the key to ATSApplicationFontsPath, the Class to String, and I tried various values including "myFont", "myFont.ttf", myFont, and myFont.ttf none of which worked. I then tried this with another font just to make sure that it wasn't the font that was the problem. Neither of the two font files have been installed.

I am totally dumbfounded as to what's going on here.
Quote this message in a reply
Member
Posts: 283
Joined: 2006.05
Post: #10
Does it work if you install the font to your system? If not, make sure you're using the right name to access it. Font Book will show you the PostScript name, which will always work.
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #11
maximile Wrote:Does it work if you install the font to your system? If not, make sure you're using the right name to access it. Font Book will show you the PostScript name, which will always work.


Thanks, I had been setting the font using the file name. But it still only works when I specify one font at a time. How would I set ATSApplicationFontsPath to use the resource folder as a directory from which to load all fonts? I tried giving an empty string to it but that doesn't work.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #12
I suggest making a subfolder of Resources instead ( yes, I know that's nearly impossible in Xcode, but you'll have to learn how at some point Wink ).
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #13
Thanks, got it working, finally.
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #14
Okay, so I've been using this method(OSC'S code) in my program to display small amounts of text, mostly labels. There's a part of my interface which displays quite a number of individual text items, and the frame rate drops from 300ish to the 30s. I believe the culprit is glTexSubImage2D since it needs to be called everytime I alter the contents of the views text. Is there some workaround to this short of creating a separate text view for every possible bit?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #15
You don't want to update the text too often. And you don't want to guess at what your performance problems are either Rasp Use OpenGL Profiler and Shark to pinpoint exactly what's the performance problem.

When you're rendering text like this, you'll generally want to keep a cache of textures for strings, so that you only have to rerender the text when you hit a genuinely new string.
Quote this message in a reply
Post Reply