CGUITTFFont reloaded

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Akabane87
Posts: 50
Joined: Sat May 05, 2012 6:11 pm

Re: CGUITTFFont reloaded

Post by Akabane87 »

Oops sorry guys. Yep I definitly forgot the delete[] texgauss; in the if scope above.

For the missing functions :

Code: Select all

 
u32 PremultiplyAlpha(u32 color)
{
    u32 a = (color>>24)/* & 0xff*/ + 1;
    u32 r = (a*((color>>16) & 0xff))>>8;
    u32 g = (a*((color>>8) & 0xff))>>8;
    u32 b = (a*(color & 0xff))>>8;
    return (--a<<24) | (r<<16) | (g<<8) | b;
}
 
void PremultiplyAlpha(irr::video::ITexture* texture)
{
    if(!texture || texture->getColorFormat() != irr::video::ECF_A8R8G8B8)
        return;
 
    u32* color = (u32*)texture->lock();
    const irr::core::dimension2d<u32>& dim = texture->getSize();
    u32 size = dim.Height*dim.Width;
    do
    {
        *color = PremultiplyAlpha(*color);
        ++color;
    }while (--size);
 
    texture->unlock();
}
 
class MathUtils
{
public:
        static float Gaussian(float x, float mu, float sigma)
    {
        return exp( -(((x-mu)/(sigma))*((x-mu)/(sigma)))/2.0f );
    }
}
 
And Rectangle2 is just a typedef I forgot to replace :

Code: Select all

typedef core::rect<s32> Rectangle2;
@Christian : I'm not sure to understand the meaning of your question. Encoding/decoding formats and rendering is 2 different things. This font is just about rendering : you give wide chars strings as parameter and you get a render result using a TTF font. Wide chars can contain every type of encoding format that can be stored on 16 bits and I don't know which one is used by irrlicht when using a wchar in core::stringw. But in any case this is not related to the rendering part.

For example : I read a text file encoded in unicode :

Code: Select all

 
FILE* file = fopen(path, "r, ccs=UNICODE");
 
// Then anything I read as wchars will be used correctly in irrlicht and can be used with the TTF font
wchar_t line[2048];
while (fgetws(line, 2048, file) != NULL) 
{
   core::stringw str(line);
}
[...]
 
If you want to do the same with UTF8, you just specify UTF8 instad of unicode when reading the file. WHat I mean is that the decoding is supposed to be done when reading or storing the strings. Not when rendering them.
Akabane87
Posts: 50
Joined: Sat May 05, 2012 6:11 pm

Re: CGUITTFFont reloaded

Post by Akabane87 »

Here is an example of the gaussian blur used under the real font rendered (semi transparent) to to produce some underlightning effect
ImageImage
Lots the blur effects are dynamic (tint or alpha pulsing to make the menus more vibrant).

These screenshots come from my latest project contribution that has just been released.
Last edited by Akabane87 on Tue Sep 09, 2014 10:06 am, edited 1 time in total.
WuZhenwei
Posts: 5
Joined: Fri Apr 18, 2014 11:08 am

Re: CGUITTFFont reloaded

Post by WuZhenwei »

I love this class. It really helps a lot. Besides, I think it's quite easy to provide a `load' function with IReadFile object, to fit the irrlicht file system better. Would you please add that too? :)
Akabane87
Posts: 50
Joined: Sat May 05, 2012 6:11 pm

Re: CGUITTFFont reloaded

Post by Akabane87 »

As you can see in the load function :

Code: Select all

bool CGUITTFace::load(const irr::io::path& filename)
{
    if ( !library )
    {
        if (FT_Init_FreeType( &library ))
        {
            return  false;
        }
    }
    core::stringc ansiFilename(filename);   // path can be anything but freetype can only work with ansi-filenames
    if (FT_New_Face( library,ansiFilename.c_str(),0,&face ))
    {
        return  false;
    }
    return  true;
}
All is done in freetype lib. We don't read the file at all in this class, but only provide to the lib an ansi filename.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: CGUITTFFont reloaded

Post by hendu »

Freetype provides an in-memory api as well, as used by the other ttf classes.
Post Reply