Text with Special Chars in bge

Hi everyone,

I’m trying to get special chars to work in bge, but I have not been able to get it all right.

I have generated a bitmap font with ftblender and mapped it to a plane. Everytime one of the additional chars has to be displayed, blender shows two chars instead.

Example:
When I want to display an ‘ä’ (Unicode Codeposition U+00E4, UTF-8 HEX-Value c3 a4), blender displays ‘Ã’ (Unicode Codepos U+00C3) and ‘¤’ (Unicode Codepos U+00A4). This happens both ingame as well as in Textured View.
I also tried to load the text from a txt-file.

Blender seems to read the Hex-Value as 32Byte. I modified the txt-file with a HEX-Editor, but then Blender is not able to read the file anymore.

On the other hand blender seems to recognize some special chars and ignores others completely (like ‘Ø’).

I tried blender 2.59 and 2.60.3 and two fonts (one from the internet), but this happens every time. I even used several encodings.

So is there a workaround or is Blender just limited there?

well if you have .ttf font file that support the special characters then this might work.

Originally meant for my language.
Just give it a shot.
blenderartists.org/forum/showthread.php?231985-BLF-Unicode-Text-File-Parser&highlight=blf+%2B+unicode

The bitmap text does not support Non-Ascii characters since 2.5. I think this is due to the Python 3 upgrade.

You can use the Font object. Unfortunately it does not support <CR> which is displayed as square. :(.

Monster, as far as I know, unicode should be fully supported by the font objects, you just need to make sure you have a font that supports the language you want to display. The default Blender font doesn’t support a huge range, but I think they’ve been looking into changing the default font.

Thank you for your help.

Karakasimov, your file is excellent. It looks much nicer than a bitmap font and works perfect. I modified it to read multiline text (this also resolves your problem with the last char).
In Case you want to see I attached the new file

@Monster: You can display non-ASCII chars in Bitmap text, but somehow not all chars. And about Font Objects: I even thought of using them, but you can’t edit them with the bge running (afaik).

Attachments

blf_unicode_test.zip (351 KB)

I haven’t seen Non-Ascii character in bitmap text with 2.5/2.6 but in 2.49.

You can edit Font object text with Python (undocumented attribute):

FontObject.text = “new text”

Logic brick access is missing

Thanks man.
also thanks for the updated version.
now my question now is how to change the colour?
hmm.

@Monster
check the file last attached. it display non ascii text!!!
you can virtually use any language you want:wink:

I’m was not talking about BLF. I was talking about the Bitmap object.

Since I need colored text, I tried a bit and recognized that you can use the SHADOW for this. Just insert


blf.enable(font_id, blf.SHADOW)
blf.shadow(font_id, blur_size, 1.0, 0.0, 0.0, 1.0)  # number -&gt; rgba

before the draw-function.
blur_size being 0 means colored Font, 3 or 5 means a colored rim around the font.
Note that you can only use (0, 3, 5).

EDIT: USING SHADOW WITH blur_size 0 DOES NOT COLOR THE WHOLE TEXT IN 2.59, BUT ONLY THE RIM

BTW, what’s the best way to ‘undraw’ the text. In the file I uploaded, I just set an empty list to be drawn:

scene.post_draw = []

Is there a proper way to achieve this (I don’t really know the blf and bgl modules)?

@Monster: I had some non ASCII chars in bitmap text in 2.6, but now I can’t manage it anymore (I haven’t saved this unfortunally). I tried some in the beginning and only few where displayed correctly, so I recommend using the blf module or Font Objects (which sadly still don’t have built-in multi-line support)

You might want to look into Bgui, which (among other things) wraps BLF. The Bgui.Label() object has color control and can be hidden or unhidden by changing it’s visibility attribute.