OpenGL Fonts

This topic is 3733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey was just wondering what would be the best way of doing fonts in opengl. I know from my time that I played around with xna and c# I was a fan of doing the spritebatch and it would cut up the image for you. Is there something similar to that in opengl?

Share on other sites
IN a word, no. you need to look into font libraries. Here, screw around with the code from nehe lesson 43

Share on other sites
Yeah . .. I rather stay away from nehe's lessons I'm not a huge fan of his style.

Share on other sites
speciesUnknown is right though, you do need some kind of ability to load a font file from the system and then convert it to a form OpenGL can handle, most likely a texture.

Look into freetype or, if you are using SDL, SDL_ttf. Moving from that representation to an OpenGL texture shouldn't be too difficult.

Share on other sites
I would go along with nehe lesson 43 also like speciesUnknown suggested. It uses the FreeType Font library which loads .ttf files and draws them. I used this tutorial and it worked perfectly (of course i modified it a lot). If you want, you can of course look through it and update/fix parts of it you want, but not using it just because it is NeHe's is really stupid I think, it works great, I have never had problems with it. Other than that though, I would go with bitmaps fonts (NeHe has a tutorial on it) or I think glut has a font thing.

Share on other sites
Quote:
 Original post by kubaplYeah . .. I rather stay away from nehe's lessons I'm not a huge fan of his style.

Ignore his style and look at what he did and glean the information you need for your application. He shows you how to load font information and use it to create a texture and then he shows you how to use display lists to render your text to the screen. You may not like HOW he did it but you can emulate WHAT he did in your own style.

Everything you need is basically right there.

Personally I wrote a helper application that allows you to select a font then it renders a stream of text to a buffer (all printable characters) and stores that buffer as RGBA data along with glyph and position information embedded in a simple custom file format. Then in my apps I open the file use the RGBA information to create a texture and use the glyph and position information to create display lists. In the font loading class I overloaded the << operators so basically all I have to do to display text is:

font.setPosition(100, 200);font << "this is my text" << endl;font.display();

I can't remember the exact functions because I don't have the code in front of me but that's about it.

1. On my Linux box the fonts are aliased so that aliasing comes through in the RGBA information.
2. If you download my game I simply need to include that custom font file with the download bundle and it doesn't matter what platform or OS you are on, the text will look the same.

Oh and I used NeHe's tutorials as a basis for formulating my own font library.

1. 1
2. 2
Rutin
20
3. 3
4. 4
frob
15
5. 5

• 9
• 9
• 13
• 9
• 33
• Forum Statistics

• Total Topics
632592
• Total Posts
3007285

×