Sign in to follow this  

Printing Unicode text with Freetype and OpenGL

This topic is 3864 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, Because my application can load different language packs, there are characters that are not in ASCII/ANSI, so I can't display them. Therefore, I must find a way to load unicode chars and make textures out of them. My question is: how can I do that with FreeType 2.0? My code now (based on a NeHe lesson) only creates 256 textures for every char that is in ANSI. But unicode has got a lot more chars. What must I do?

Share this post


Link to post
Share on other sites
Unicode is a bit of a problem because it's just huge. You can't feasibly create a texture with all the unicode characters for a font. However, in any one language pack, only a small proportion of the available characters will be used, so one way to deal with it is to scan through the language pack when you load it, and build a list of the characters that are actually used, and then build your texture containing just those characters.
If you're letting players enter text during the game though, then you might have a problem. You could limit players to only entering ASCII chars and make sure you always include the ASCII set in your font texture, or include the whole of latin-1 to allow for a few more languages. If you want people to be able to enter any character though, then you'll either have to use FreeType to render that text directly, or update your font textures during the game to include characters that weren't needed before (maybe have a separate texture that you update with the 'extra' characters).

John B

Share this post


Link to post
Share on other sites
Sounds like a plan. But how do I let the system remember the position in the texture array of a certain symbol?

And when I read the language text from the .txt file, should I use wchar_t instead of char?

Share this post


Link to post
Share on other sites
Quote:
Original post by Revelation60
That's not really an option, since I don't know what language packs the player adds. :(

I'm not sure I understand why BMFont is not an option - it can generate font textures from TrueType UNICODE fonts. It also can pack the characters so that you have a minimum number of textures. It can even pack it all in different color-channels of a single texture file. Basically, If you use BMFont - you don't need to worry about generating the character textures and all you would have to do is load the textures (and font file) and then use it to render the text.

Quote:
Original post by Revelation60
Sounds like a plan. But how do I let the system remember the position in the texture array of a certain symbol?

You could have a std::map, or some other associative container for that.

Quote:
Original post by Revelation60
And when I read the language text from the .txt file, should I use wchar_t instead of char?

That depends - you can handle it all as UTF-8, then you read it into char buffers, but then you'd still need to get the correct character codes, so I guess it would be easier to use wchar_t (UCS-16) from the beginning.

Share this post


Link to post
Share on other sites

This topic is 3864 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this