get all characters from a font

Started by
5 comments, last by Yours3!f 12 years, 8 months ago
hi,

how do I load all the characters from a font using freetype (2) ?
I can already load a range of them (0...255), and also display them, I just don't know how to get all of them.

Best regards,
Yours3!f
Advertisement
As far as I remember, the FT_Face::num_glyphs contains the number of individual glyphs in the face. You can make loop from 0 up to, but not including, that number and pass the loop index to FT_Load_Glyph. Keep in mind though that the loop index is the glyph index, and it may or may not be related to any specific character code (which is what you get from, say, looping over the characters of a string which contains a sequence of ASCII character codes). I do not how to translate a glyph index to a character code, but a character code can be translated to a glyph index with FT_Get_Char_Index.
<br />As far as I remember, the <i>FT_Face::num_glyphs</i> contains the number of individual glyphs in the face. You can make loop from 0 up to, but not including, that number and pass the loop index to <i>FT_Load_Glyph</i>. Keep in mind though that the loop index is the <i>glyph index</i>, and it may or may not be related to any specific character code (which is what you get from, say, looping over the characters of a string which contains a sequence of ASCII character codes). I do not how to translate a glyph index to a character code, but a character code can be translated to a glyph index with <i>FT_Get_Char_Index</i>.<br />


Thanks Bob, I already use num glyphs, which is, as you said wrong, because it messes up character codes. I'd need the glyph index -> character codes conversion or maybe a string that contains all possible characters from a keyboard (but that won't include characters from other keyboards...).

BTW the rendering is pretty nice, since I use VBOs and VAOs. I don't know whether it affects performance, but if I load "num_glyphs" (~30.000) number of characters, then I create 30.000 VAOs + 30.000*4 VBOs :)
One VAO and VBO for each character? Put them all in one VBO instead, and use indices to reference the individual glyphs.

One VAO and VBO for each character?



May I also ask what do you need all the characters for anyway?

WBW, capricorn
Thanks for the advice!<br /><br />That's a good question <img src='http://public.gamedev.net/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' /> I obviously don't need that many characters, but I do need some... I just used a brute-force method <img src='http://public.gamedev.net/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />

EDIT: I have 30k textures as well...
I think I found the solution here:<br /><a href='http://www.gamedev.net/topic/571270-freetype-2-creating-a-hash-map-to-access-glyphs-from-unicode-characters/' class='bbc_url' title=''>http://www.gamedev.n...ode-characters/</a><br /><br />and using that code I made this:<br /><br />
    FT_UInt index;<br />
    FT_ULong code = FT_Get_First_Char(ftface, &amp;index);<br />
    <br />
    std::vector&lt; FT_ULong &gt; character_codes;<br />
    character_codes.resize(1);<br />
    character_codes[0] = code;<br />
    <br />
    while( index != 0 )<br />
    {<br />
        character_codes.resize(character_codes.size() + 1);<br />
        character_codes[character_codes.size() - 1]  = FT_Get_Next_Char(ftface, character_codes.size() - 2, &amp;index);<br />
    }<br />
    characters.resize ( character_codes.size() );<br />
    int channels = 2;<br />
<br />
    for ( int c = 0; c &lt; characters.size(); c++ )<br />
    {<br />
       //loading glyphs<br />
    }<br />
<br /><br />as the freetype tutorial said a glyph index may not be a character code, which turned out to be absolutely true, now I have 65535 characters... (which is the max size of a unsigned short right?)

(and consumes about 500MB of memory)

This topic is closed to new replies.

Advertisement