• Advertisement
Sign in to follow this  

get all characters from a font

This topic is 2355 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,

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

Share this post


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

Share this post


Link to post
Share on other sites
[quote name='Brother Bob' timestamp='1312915923' post='4846813']<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 />[/quote]

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 :)

Share this post


Link to post
Share on other sites
[quote name='Brother Bob' timestamp='1312923255' post='4846884']
One VAO and VBO for each character?
[/quote]


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

Share this post


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

Share this post


Link to post
Share on other sites
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 />[code]<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 />
[/code]<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)

Share this post


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

  • Advertisement