Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Using TrueType Fonts.

This topic is 2505 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

I am currently trying to get true-type fonts implemented in my Rendering Engine. I'm not sure on how to approach this, I've done a lot of Google-ing and from what I've read I can load a Texture from the True Type Font (.ttf) into VRAM for OpenGL to use and then draw each character with a quad or something similar, cropped appropriately (probably storing dimensions of where to crop each character in RAM, instead of calculating on the spot? S: e.g. Where along the x axis to crop to the actual pixels of the letter). Now I was thinking of doing it this way, but how would I dynamically make the font bolt or italic, I would have to re-load the texture into memory wouldn't I, or just put them side by side, or something? I don't know S:.

Now I've read somewhere, can't remember where that I could generate geometry from the font or something? I don't know, but would this be easier than doing what I mentioned above, if so, why? Also how should I implement that, I'm not sure on how to go on that. Would it be better than rendering each character as a quad from a texture, or drawing the text as geometry.

Many thanks for reading. (:

Share this post

Link to post
Share on other sites
hehe, you are approaching a very, very difficult part of opengl rendering...

first you load in the fonts using freetype, this should be relatively easy using the nehe tutorials or other sources...
here are the methods for rendering fonts from least difficult (slowest) to most difficult (fastest):
-render using immediate mode: this should be pretty straightforward, but very slow... you just have to render textures on top of quads
-render using VBOs (and VAOs): this is a bit more difficult, but can be done... requires caching of font data i.e. textures (you can draw them using one appropriately scaled and positioned quad)
-cache the textures using a texture atlas: so this time you have to cache the textures from the fonts into a large texture that holds contains them all. you can access each individual texture by using texture coordinates, so this requires caching the quads (with appropriate sizes and texture coordinates)
this is getting more and more difficult right?
-render fonts using compositing: this is the last step, which involves a window sized texture onto which you can render your fonts (and your GUI too!), the trick comes here: you only have to update those parts of the texture which require it, that is where you placed a new character or deleted one. This compositing system is used by many GUIs such as the one you can find on Windows, but there are others for example on linux: KDE, XFCE, LXDE, Gnome. This is very difficult to implement properly, but if done well it is very fast. You can also render you fonts on a separate thread, and only update the texture that is actually rendered to the screen when you are ready with rendering the changes.

Best regards,

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!