Problem trying to use a custom font for the GUI

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
tronfortytwo
Posts: 5
Joined: Wed Nov 01, 2017 7:17 pm

Problem trying to use a custom font for the GUI

Post by tronfortytwo »

Hi! This is my first project using Irrlicht.

I created a device and I am trying to create a GUI, but I fail to set a custom font as the one in use.
This is my code:

Code: Select all

 
    irr::gui::IGUIFont *tatofont;
    // guienv is the IGUIEnvironment pointer
    guienv->addFont("../data/fonts/Dashley.ttf", tatofont);
    
    if (tatofont)
         // skin is the IGUISkin pointer
        skin->setFont(tatofont);
    
    skin->setFont(guienv->getBuiltInFont(), irr::gui::EGDF_TOOLTIP);
    
    // background image
    guienv->addImage(
         // driver is the IVideoDriver pointer
        driver->getTexture("../data/artwork/background.jpg"),
        irr::core::position2d<int>(0,0) );
    
    // title
    guienv->addStaticText(
        L"TATO ADVENTURES",
        irr::core::rect<irr::s32>(10,10, window_x, window_y) );
    
    // new game button
    guienv->addButton(
        irr::core::rect<irr::s32>(20, 50, window_x/3, 70), 0, BUTTON_NEW,
        L"NEW GAME", L"Start the adventure!" );
        
    // quit button
    guienv->addButton(
        irr::core::rect<irr::s32>(20, 90, window_x/3, 110), 0, BUTTON_QUIT,
        L"QUIT", L"You really want to leave us?" );
    
    // render it all
    // device is the IrrlichtDevice pointer
    while(device->run() && driver)
        if (device->isWindowActive())
        {
            driver->beginScene(true, true, irr::video::SColor(0,200,200,200));
 
            guienv->drawAll();
    
            driver->endScene();
        }
 
Stdout doesn't print any error, and in fact everything works as expected. The only problem is that the font used by the GUI is still the default one, and not the one I loaded. I tryed also with a .bmp font with the same result. Thank you very much to anyone helps me out :)
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: Problem trying to use a custom font for the GUI

Post by MartinVee »

IGUIEnvironment::addFont adds a previously loaded font see reference. The "name" parameter is just the internal name of your font, and it's not a file path. The code as it is just pass an invalid (probably null) pointer to the addFont method, which probably does absolutely nothing since it's null.

Although Irrlicht doesn't support TTF Font, you can use the excellent CGUITTFont class (that you can find here). It's easy to integrate and use, and brings with it a nice i18n library!
tronfortytwo
Posts: 5
Joined: Wed Nov 01, 2017 7:17 pm

Re: Problem trying to use a custom font for the GUI

Post by tronfortytwo »

Thank you so much! You're right, I was missing a piece, now it does work. Thank you also for suggesting me the CGUITTFont class, I'll use it.
Post Reply