View Full Version : Fonts with OpenGL & GLF
Jones
2006.07.03, 02:23 PM
I've been researching ways to do fonts in OpenGL. So far I've read about bitmapped fonts, and pixmapped fonts. In my searches I found this thread:
http://www.idevgames.com/forum/showthread.php?t=11462&highlight=OpenGL+fonts
Which has several methods in it. However, several I could not find on google. Others apear to be Mac Specific. I want to keep my projects as cross platform as possible.
I'm about to try GLF, as it appears to be easy to include in a project, something I value tremendously. (sp?)
Aside from that one, I know about FreeType and SDL_font. Could I send fonts from SDL_Font to openGL textures? That would be really cool.
I've also looked at NeHe's tutorial:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13
But like all of them, it uses Windows Classes which I do not have readily available.
Anyway, in short, is GLF a good way to go? If not, what is better? Keep in mind that I am not using Cocoa. That is why I need a font system, to make my own OpenGL interface system.
Thanks!
akb825
2006.07.03, 02:47 PM
IIRC, GLF requires FreeType 1. You should try out FTGL (http://homepages.paradise.net.nz/henryj/code/#FTGL), which uses FreeType 2. However, you should probably use my build here (http://akb825.com/downloads/FTGL.zip), which has FreeType 2 built in, so you don't have to worry about the extra library. It is already set up to be used as a Universal Binary, and I can assure you it works. It uses C++ for the interface, but if you use ObjectiveC++ (with a .mm file extension), you should have no problems using it.
Jones
2006.07.03, 04:19 PM
Oh wow, thanks for those links! Is FTGL something that would work in a windows program, with a windows build of FreeType?
Also, if you could clarify something...
When I download FTGl or say GLF, do I need to build anything (other than FreeType), or can I just drop the headers in as indicated?
Thanks!
akb825
2006.07.03, 04:43 PM
If you build the a Windows version of FTGL with a Windows version of Freetype, then it shouldn't have any problems. In fact, the build that I have, if you set up the files similarly, should compile as well. The only thing is you would have to replace the UNIX-specific source file with the Windows specific source file.
If you already have a pre-compiled version of FTGL or GLF, you won't have to build anything. Otherwise, you will: the headers aren't enough, since they don't actually provide any of the code necessary to do the functions that are declared.
Jones
2006.07.03, 06:46 PM
Ok then. I noticed on the GLF site they mentioned it was good because it only needed to headers to work. True... but two headers + FreeType. Does the FTGL.framework that I assume you compiled, from the link you gave me have FreeType built into it?
Thanks!
OneSadCookie
2006.07.03, 06:56 PM
Reading comprehension is clearly not your strong point.
akb825
2006.07.03, 07:09 PM
Ok then. I noticed on the GLF site they mentioned it was good because it only needed to headers to work. True... but two headers + FreeType. Does the FTGL.framework that I assume you compiled, from the link you gave me have FreeType built into it?
Thanks!
Yes, as I've said before. However, the only headers you need to include for FTGL are for the class you need. For example, if you only want polygon fonts, you can just include FTGLPolygonFont.h, and that's all you need.
Jones
2006.07.03, 07:27 PM
Reading comprehension is clearly not your strong point.
Well, I am sorry, but I wasn't sure what he meant by "the extra library". I see now that it was probably the font lib. I am grateful for the explanations provided here.
Thanks.
EDIT:
That, and the fact that I only have experience with frameworks jam packed with headers. When I find one with a lack of those, I wonder if they are seperate, or something else is needed/must be compiled.
Please try to remember that I am a novice, with little experience in this sort of thing.
akb825
2006.07.03, 08:10 PM
You can create a folder in the framework called Headers and put the headers in there if you want them readily accessible. I'm not 100% sure what copy files phase you need to put them in there. (there's headers in the "Copy Headers" section, but they don't appear to actually be copied...)
Jones
2006.07.04, 01:28 PM
Yeah, I tried that. But I don't I'm setting it up right... I've dropped the FTGL framework (universal) into my /Library/Frameworks folder. I then added it to my project, along with the "freetype include" and "include" headers. (Directly all into my project folder). But it would appear that FTGL can't find FreeType. Here are some sample errors:
Missing freetype classes...
FTFace.h:103: error: 'FT_GlyphSlot' does not name a type
FTFace.h:115: error: 'FT_Error' does not name a type
FTFace.h:121: error: ISO C++ forbids declaration of 'FT_Face' with no type
FTFace.h:121: error: expected %<;%> before '*' token
FTFace.h:133: error: ISO C++ forbids declaration of 'FT_Encoding' with no type
FTFace.h:133: error: expected %<;%> before '*' token
FTFace.h:143: error: 'FT_Error' does not name a type
FTFont.h:87: error: `FT_Encoding' has not been declared
FTFont.h:101: error: ISO C++ forbids declaration of 'FT_Encoding' with no type
FTFont.h:101: error: expected %<;%> before '*' token
FTFont.h:217: error: 'FT_Error' does not name a type
FTFont.h:251: error: 'FT_Error' does not name a type
Not understanding that stuff...
FTPoint.h:5:10: error: #include expects "FILENAME" or <FILENAME>
FTPoint.h:6:10: error: #include expects "FILENAME" or <FILENAME>
This appears to be missing...
/Users/gareth/Desktop/sdlContext/ft2build.h:34:38: error: freetype/config/ftheader.h: No such file or directory
And yet, there it is, in that folder. (It's placed so that all the paths would work.)
I'm sorry for needing so much help with this, but it is much appreciated.
akb825
2006.07.04, 01:34 PM
No, not to your project, to the framework. Have a Headers folder in the framework, and just dump the contents of the two header folders into there.
Jones
2006.07.04, 01:49 PM
No, not to your project, to the framework. Have a Headers folder in the framework, and just dump the contents of the two header folders into there.
Did that, at first it didn't work. Then I added the FTGL framework headers folder to my search directories, and it compiles! Huzzah!
Thanks a ton for this!
akb825
2006.07.04, 02:06 PM
No problem. Actually, looking at the structures, it looks like the correct way to do it (without having to add the headers to the search path) is to put the Headers folder under FTGL.framework/Versions/A, then put an alias under the root directory of the framework. I thought it would just look at that alias for the headers, but I guess it looks at the version rather than what's currently being used as the alias. Regardless of where you put the headers, if you add the folders to your search path, you can use the <> notation of include rather than "".
Jones
2006.07.05, 02:51 PM
Yeah, thanks. That'll be useful if I ever distribute the game.
I think I'm doing something wrong though, the FAQ and the readme both say this is how to do it:
FTGLPixmapFont font;
font.Open( "Fonts:Arial");
font.FaceSize( 72);
font.render( "Hello World!");
And I am doing so, except that .render must actually be .Render. But anyway, it says that FTGLPixmapFont, or BitmapFont for that matter has no Open class. I've never done anything with oop classes, but I do now how to make one, and what a class would look like. And it's true (I checked), neither class has a .Open function. Nor a .open or .load or related commands.
Am I missing a piece of the puzzle? :???:
(Note: I have all the FTGL stuff included, every single header.)
Jones
2006.07.05, 03:30 PM
Ok, after a quick analysis of how the classes work, and classes in general. I realized the docs are a bit outdated. You actually load them up like this:
FTGLBitmapFont font("your-font-here");
There is no "open" function. :)
akb825
2006.07.05, 03:32 PM
It should indeed be .Render. To create a new font, you use the constructor, passing in the path to the font file.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.