Jump to content
  • Advertisement
Sign in to follow this  
kubapl

OpenGL Fonts

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by kubapl
Yeah . .. 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.

This gives me two advantages.

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!