Jump to content
  • Advertisement
Sign in to follow this  
warserver

Freetype2 and OpenGL

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

Hi all, I want to use the Freetype2 library for my OpenGL GUI to keep my code portable and use antialiased text. The thing I did, was creating a Font object that reads a face from a given font file. Now the object should load all the glyphs for all characers ( more than ASCII ) from the face into a single OpenGL texture. This texture will then be used to generate display lists for a string. I've read NeHe lesson #43 as well as the Freetype2 tutorial, but still I'm stuck. The problem is that every glyph has got a different size.. ( width, height ). Since I want every character in the texture to have the same size I would need to figure out first which character has the biggest dimensions and use those dimensions for every character in the texture. Isn't there a more elegant solution than this? Or is there a better approach than mine (loading all charactes into a single texture)? I hope I discribed my problem good enough... if you need additional information, please ask. I'm not a professional programmer, so I might have missunderstood parts of the freetype2 tutorial (which is very confusing to me). Thanks in advance, Alex.

Share this post


Link to post
Share on other sites
Advertisement
It's not really clear from the FreeType doc's, but when you call FT_Set_Pixel_Sizes you are setting the size of the bounding box holding all the glyphs in that font. So after calling e.g. FT_Set_Pixel_Sizes(face, 0, 16), all glyphs rendered will fit inside a 16x16 px bounding box
  • .

    Then, when you've rendered your glyph you use the "left" and "top" members of the glyph bitmap to get the right position of the glyph in the bitmap.

  • Except, maybe, some very high glyphs like Ä or Š. I'm not sure about those.

    Share this post


    Link to post
    Share on other sites
    You're right, that isn't very clear from the Freetyp docs...
    Unfortunately for me, I'm not a C++ programmer and didn't understand the code of FTGL or other free libraries merging OpenGL and Freetype.
    Anyway thank you very much, I'll try to use FT_Set_Pixel_Sizes() instead of FT_Set_Char_Size() and see if it solves the problem. I'm still having difficulties with understanding the coherences between the glyph's metrics, the glyph's bounding box, the face's bounding box and "left and "top" of the BitmapGlyph struct aso.
    But before bothering you again, I'll try to understand them better.

    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.

    We are the game development community.

    Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

    Sign me up!