blender/source/gameengine/Rasterizer
Dalai Felinto 0890b80ed9 Patch:[#25163] BGE support for Blender Font objects - unicode support
Problem/Bug:
------------
There were no way to have proper unicode characters (e.g. Japanese) in Blender Game Engine. Now we can :)
You can see a sample here: http://blog.mikepan.com/multi-language-support-in-blender/

Functionality Explanation:
--------------------------
This patch converts the Blender Font Objects to a new BGE type: KX_FontObject
This object inherits KX_GameObject.cpp and has the following properties:
- text (the text of the object)
- size (taken from the Blender object, usually is 1.0)
- resolution (1.0 by default, maybe not really needed, but at least for debugging/the time being it's nice to have) 

The way we deal with linked objects is different than Blender. In Blender the text and size are a property of the Text databock. Therefore linked objects necessarily share the same text (and size, although the size of the object datablock affects that too). In BGE they are stored and accessed per object. Without that it would be problematic to have addObject adding texts that don't share the same data.

Known problems/limitations/ToDo:
--------------------------------
1) support for packed font and the <builtin>
2) figure why some fonts are displayed in a different size in 3DView/BGE (BLF)
3) investigate some glitches I see some times
4) support for multiline
5) support for more Blender Font Object options (text aligment, text boxes, ...)

[1] Diego (bdiego) evantually will help on that. For the time being we are using the "default" (ui) font to replace the <builtin>.
[2] but not all of them. I need to cross check who is calculating the size/dpi in/correctly - Blender or BLF. (e.g. fonts that work well - MS Gothic)
[3] I think this may be related to the resolution we are drawing the font
[4] It can't/will not be handled inside BFL. So the way I see it is to implement a mini text library/api that works as a middlelayer between the drawing step and BLF. 
    So instead of:
      BLF_draw(fontid, (char *)text, strlen(text));
    We would do:
      MAGIC_ROUTINE_IM_NOT_BLF_draw(fontir, (char *)text, styleflag, width, height);
[5] don't hold your breath ... but if someone wants to have fun in the holidays the (4) and (5) are part of the same problem.

Code Explanation:
-----------------
The patch should be simple to read. They are three may parts:
1) BL_BlenderDataConversion.cpp:: converts the OB_FONT object into a KX_FontObject.cpp and store it in the KX_Scene->m_fonts
2) KetsjiEngine.cpp::RenderFonts:: loop through the texts and call their internal drawing routine.
3) KX_FontObject.cpp::
  a) constructor: load the font of the object, and store other values.
  b) DrawText: calculate the aspect for the given size (sounds hacky but this is how blf works) and call the render routine in RenderTools
4) KX_BlenderGL.cpp (called from rendertools) ::BL_print_game_line:: Draws the text. Using the BLF API

*) In order to handle visibility of the object added with AddObject I'm adding to the m_scene.m_fonts list only the Fonts in a visible layer - unlike Cameras and Lamps where all the objects are added.

Acknowledgements:
----------------
Thanks Benoit for the review and adjustment suggestions.
Thanks Diego for the BFL expertise, patches and support (Latin community ftw)
Thanks my boss for letting me do part of this patch during work time. Good thing we are starting a project in a partnership with a Japanese Foundation and eventual will need unicode in BGE :) for more details on that - www.nereusprogram.org - let's call it the main sponsor of this "bug feature" ;)
2010-12-16 10:25:41 +00:00
..
RAS_OpenGLFilters correct fsf address 2010-02-12 13:34:04 +00:00
RAS_OpenGLRasterizer use lowercase for cmake builtin names and macros, remove contents in else() and endif() which is no longer needed. 2010-12-08 08:43:06 +00:00
CMakeLists.txt use lowercase for cmake builtin names and macros, remove contents in else() and endif() which is no longer needed. 2010-12-08 08:43:06 +00:00
Makefile Update address in license block. 2010-08-10 21:22:26 +00:00
RAS_2DFilterManager.cpp A couple of changes to 2D filters to make adding new built-in ones nicer: 2010-11-01 00:15:12 +00:00
RAS_2DFilterManager.h - WITH_CXX_GUARDEDALLOC working again 2010-06-06 01:15:44 +00:00
RAS_BucketManager.cpp update for MingW/CMake 2010-09-15 16:13:32 +00:00
RAS_BucketManager.h BGE: When dynamically loading scenes (bge.logic.LibLoad()) in GLSL mode, the lights in the loaded scene would not affect the current scene and vice versa. To fix this, I've updated to merge code to update the scenes that the shaders are using to the scene being merged into. 2010-06-16 19:07:20 +00:00
RAS_CameraData.h use BLI_findstring in more places & remove some warnings, no functional changes. 2010-02-22 09:22:36 +00:00
RAS_Deformer.h update for MingW/CMake 2010-09-15 16:13:32 +00:00
RAS_FramingManager.cpp remove config.h references, was added for automake build system rev around 124-126 but isnt used by any build systems now. 2010-04-18 10:28:37 +00:00
RAS_FramingManager.h - WITH_CXX_GUARDEDALLOC working again 2010-06-06 01:15:44 +00:00
RAS_ICanvas.h - WITH_CXX_GUARDEDALLOC working again 2010-06-06 01:15:44 +00:00
RAS_IPolygonMaterial.cpp remove config.h references, was added for automake build system rev around 124-126 but isnt used by any build systems now. 2010-04-18 10:28:37 +00:00
RAS_IPolygonMaterial.h - WITH_CXX_GUARDEDALLOC working again 2010-06-06 01:15:44 +00:00
RAS_IRasterizer.h update for MingW/CMake 2010-09-15 16:13:32 +00:00
RAS_IRenderTools.cpp correct fsf address 2010-02-12 13:34:04 +00:00
RAS_IRenderTools.h Patch:[#25163] BGE support for Blender Font objects - unicode support 2010-12-16 10:25:41 +00:00
RAS_LightObject.h correct fsf address 2010-02-12 13:34:04 +00:00
RAS_MaterialBucket.cpp update for MingW/CMake 2010-09-15 16:13:32 +00:00
RAS_MaterialBucket.h - WITH_CXX_GUARDEDALLOC working again 2010-06-06 01:15:44 +00:00
RAS_MeshObject.cpp correct fsf address 2010-02-12 13:34:04 +00:00
RAS_MeshObject.h update for MingW/CMake 2010-09-15 16:13:32 +00:00
RAS_ObjectColor.h correct fsf address 2010-02-12 13:34:04 +00:00
RAS_Polygon.cpp update for MingW/CMake 2010-09-15 16:13:32 +00:00
RAS_Polygon.h - WITH_CXX_GUARDEDALLOC working again 2010-06-06 01:15:44 +00:00
RAS_Rect.h - WITH_CXX_GUARDEDALLOC working again 2010-06-06 01:15:44 +00:00
RAS_texmatrix.cpp remove config.h references, was added for automake build system rev around 124-126 but isnt used by any build systems now. 2010-04-18 10:28:37 +00:00
RAS_TexMatrix.h correct fsf address 2010-02-12 13:34:04 +00:00
RAS_TexVert.cpp correct fsf address 2010-02-12 13:34:04 +00:00
RAS_TexVert.h - WITH_CXX_GUARDEDALLOC working again 2010-06-06 01:15:44 +00:00
SConscript rename libs internal libs for CMake + SCons (used in MSVC project files) 2010-11-18 11:42:05 +00:00