my way to use it in irrlicht-1.1:
1) download and build freetype-2.2.1
2) copy CGUITTFont.cpp and CGUITTFont.h to "..\irrlicht-1.1\source"
3) compare all the other .cpp and .h files in IrrTT with their correspondences in irrlicht-1.1 by using a file-compare tool(I use Beyond.Compare). Update the correspondence files in irrlicht-1.1 to match irrTT. Pay attention to the "font" concerned codes.
4) add CGUITTFont.cpp and CGUITTFont.h to your compiler IDE(I use VS 2005). add reference to freetype's .h and .lib files.
5) build irrlicht. if encounter error, please check the step 3).
6) try the JPtester example in irrTT.
7) JPtester runs ok in my machine, but throws an error when exits in debug mode. I check it, found the reason:
--- Error Reason ----
in "bool CGUITTFont::attach(CGUITTFace *Face,u32 size)"
the member array "Glyphs" of CGUITTFont is allocated a continuous memeory buffer by using "reallocate" method of array. The elements of Glyphs are not initialized sufficiently, e.g., the pointers "tex", "tex16" and "image" are not set to NULL and the debug name is not set to "CGUITTGlyph". Furthermore, because class "CGUITTGlyph" has virtual funcions, so the virtual function pointers(__vfptr) of each element in Glyphs should be initialized. Without the constructor of CGUITTGlyph, we have to set the __vfptr manually. My solution is shown as below:
--- My Naive Solution---
- Code: Select all
...
void CGUITTGlyph::init()
{
#ifdef _DEBUG
setDebugName("CGUITTGlyph");
#endif
tex = NULL;
tex16 = NULL;
image = NULL;
}
...
bool CGUITTFont::attach(CGUITTFace *Face,u32 size)
{
if (!Driver)
return false;
if (attached){
tt_face->drop();
}
tt_face = Face;
tt_face->grab();
this->size = size;
CGUITTGlyph tmp; // for access the __vfptr of CGUITTGlyph
int*tmp2;
Glyphs.reallocate(tt_face->face->num_glyphs);
Glyphs.set_used(tt_face->face->num_glyphs);
for (int i = 0;i < tt_face->face->num_glyphs;i++){
Glyphs[i].Driver = Driver;
Glyphs[i].size = size;
Glyphs[i].face = &(tt_face->face);
Glyphs[i].cached = false;
tmp2 = (int*)&(Glyphs[i]);
*tmp2 = *(int*)(&tmp);// the __vfptr is arranged in the front of the memory block by VC++
Glyphs[i].init(); // initialize the other memebers
// Glyphs[i].cache((wchar_t)i + 1);
}
attached = true;
return true;
}
...
NOTE:
i) You have to comment out "fonts[i]->drop();" in the end of JPtester to make it work.
ii) I only test it in VS 2005, winxp sp2. maybe it only works in windows platform.
iii) There are definitely much room to optimize.
iv) If the solution does not work for you, please wait for the officially new version which must be cleaner and correct.
--- Hope ----
Hope the admin of Irrlicht add officially surpport to Unicode Text input and render.
Localized font will make a 3D engine cute and kind to many users around the world and make the users express themselves freely.