Custom font(s) not working? (XML)

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Custom font(s) not working? (XML)

Post by Cube_ »

I tried loading a custom font.
the loading seems to work. but whenever font->draw is called the application crashes.

I am positive I did it correctly! (Doesn't REALLY matter though. I will be using this font as the only font anyway. so I could just repalace it....)
"this is not the bottleneck you are looking for"
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom font(s) not working? (XML)

Post by CuteAlien »

You neither tell us anything about your code nor do you even post the font-file which crashes. I suppose the only way we can help you is using magic...
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Custom font(s) not working? (XML)

Post by Cube_ »

ok. I will post everything for now. sleep. **Posting first thing tomorrow!**
"this is not the bottleneck you are looking for"
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Custom font(s) not working? (XML)

Post by Cube_ »

as I promised. here is the code:

Code: Select all

/*
The program will show how to use the
basics of the VideoDriver, the GUIEnvironment and the
SceneManager.
 
To use the engine, we will have to include the header file
irrlicht.h, which can be found in the Irrlicht Engine SDK
directory \include.
*/
#include <irrlicht.h>
#include "driverChoice.h"
#include "q3factory.h"
#include "sound.h"
 
#define swprintf _snwprintf
 
/*
In the Irrlicht Engine, everything can be found in the namespace
'irr'. So if you want to use a class of the engine, you have to
write an irr:: before the name of the class. For example to use
the IrrlichtDevice write: irr::IrrlichtDevice. To get rid of the
irr:: in front of the name of every class, we tell the compiler
that we use that namespace from now on, and we will not have to
write that 'irr::'.
*/
using namespace irr;
 
/*
There are 5 sub namespaces in the Irrlicht Engine. Take a look
at them, you can read a detailed description of them in the
documentation by clicking on the top menu item 'Namespace List'
or using this link: http://irrlicht.sourceforge.net/docu/namespaces.html.
Like the irr Namespace, we do not want these 5 sub namespaces now,
to keep this example simple. Hence we tell the compiler again
that we do not want always to write their names:
*/
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
/*structure for holding some GUI controls....*/
struct SAppContext
{
    IrrlichtDevice*device;
};
//Some values for identifying individual GUI controls.
enum
{
    GUI_ID_QUIT_BUTTON = 101,
    GUI_ID_NEW_WINDOW_BUTTON
};
 
 
class MyEventReceiver: public IEventReceiver
{
    public:
        MyEventReceiver(SAppContext&context):Context(context){}
        virtual bool OnEvent(const SEvent&event)
 
        {
         if(event.EventType==EET_GUI_EVENT)
         {
             s32 id=event.GUIEvent.Caller->getID();
             IGUIEnvironment*guienv=Context.device->getGUIEnvironment();
             if(event.GUIEvent.EventType==EGET_BUTTON_CLICKED)
             {
                 if(id==GUI_ID_QUIT_BUTTON)
                 {
                     Context.device->closeDevice();
                     return true;
                 }
                 if(id==GUI_ID_NEW_WINDOW_BUTTON)
                 {
                     IGUIWindow*window=guienv->addWindow(rect<s32>(100,100,300,200),false,L"NEW WINDOW!");
                     return true;
                 }
             }
         }
         return false;
        }
        private:
        SAppContext&Context;
};
 
/*
This is the main method. We can use void main() on every platform.
On Windows platforms, we could also use the WinMain method
if we would want to get rid of the console window, which pops up when
starting a program with main(), but to keep this example simple,
we use main().
*/
int main(int argc, char** argv)
{
    /*
    The most important function of the engine is the 'createDevice'
    function. The Irrlicht Device can be created with it, which is the
    root object for doing everything with the engine.
    createDevice() has 7 paramters:
    deviceType: Type of the device. This can currently be the Null-device,
       the Software device, DirectX8, DirectX9, or OpenGL. In this example we use
       EDT_SOFTWARE, but to try out, you might want to change it to
       EDT_NULL, EDT_DIRECTX8 , EDT_DIRECTX9, or EDT_OPENGL.
    windowSize: Size of the Window or FullscreenMode to be created. In this
       example we use 640x480.
    bits: Amount of bits per pixel when in fullscreen mode. This should
       be 16 or 32. This parameter is ignored when running in windowed mode.
    fullscreen: Specifies if we want the device to run in fullscreen mode
       or not.
    stencilbuffer: Specifies if we want to use the stencil buffer for drawing shadows.
    vsync: Specifies if we want to have vsync enabled, this is only useful in fullscreen
      mode.
    eventReceiver: An object to receive events. We do not want to use this
       parameter here, and set it to 0.
    */
 
    IrrlichtDevice *device =
        createDevice(EDT_SOFTWARE, dimension2d<u32>(800, 600), 16,
            false, false, false, 0);
            if (!device) return 1;
 
    /*
    Set the caption of the window to some nice text. Note that there is
    a 'L' in front of the string. The Irrlicht Engine uses wide character
    strings when displaying text.
    */
    device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
 
    /*
    Get a pointer to the video driver, the SceneManager and the
    graphical user interface environment, so that
    we do not always have to write device->getVideoDriver(),
    device->getSceneManager() and device->getGUIEnvironment().
    */
    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
 
 
 
    //Custom font :D
    IGUIFont*font = guienv->getFont("Arial.xml");
 
    //Adding an irrlicht logo :D
    ITexture*image=driver->getTexture("../../media/irrlichtlogo2.png");
 
    /*
    We add a hello world label to the window, using the GUI environment.
    */
    guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
        rect<int>(10,10,200,22), true);
 
    guienv->addButton(rect<s32>(250,20,250 +120,50),0,GUI_ID_QUIT_BUTTON,L"EXIT",L"EXITS THE GAME");
    guienv->addButton(rect<s32>(400,20,400 +120,50),0,GUI_ID_NEW_WINDOW_BUTTON,L"NEW WINDOW",L"OPENS A NEW WINDOW");
 
    SAppContext context;
    context.device=device;
    MyEventReceiver receiver(context);
    device->setEventReceiver(&receiver);
 
 
 
    /*
    To display something interesting, we load a Quake 2 model
    and display it. We only have to get the Mesh from the Scene
    Manager (getMesh()) and add a SceneNode to display the mesh.
    (addAnimatedMeshSceneNode()). Instead of writing the filename
    sydney.md2, it would also be possible to load a Maya object file
    (.obj), a complete Quake3 map (.bsp) or a Milshape file (.ms3d).
    By the way, that cool Quake 2 model called sydney was modelled
    by Brian Collins.
    */
    IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
    IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
 
    /*
    To let the mesh look a little bit nicer, we change its material a
    little bit: We disable lighting because we do not have a dynamic light
    in here, and the mesh would be totally black. Then we set the frame
    loop, so that the animation is looped between the frames 0 and 310.
    And at last, we apply a texture to the mesh. Without it the mesh
    would be drawn using only a color.
    */
    if (node)
    {
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setFrameLoop(0, 310);
        node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
    }
 
    /*
    To look at the mesh, we place a camera into 3d space at the position
    (0, 30, -40). The camera looks from there to (0,5,0).
    */
    smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
 
    /*
    Ok, now we have set up the scene, lets draw everything:
    We run the device in a while() loop, until the device does not
    want to run any more. This would be when the user closed the window
    or pressed ALT+F4 in windows.
    */
    while(device->run())
    {
        /*
        Anything can be drawn between a beginScene() and an endScene()
        call. The beginScene clears the screen with a color and also the
        depth buffer if wanted. Then we let the Scene Manager and the
        GUI Environment draw their content. With the endScene() call
        everything is presented on the screen.
        */
 
 
 
        driver->beginScene(true, true, SColor(255,128,128,128));
        driver->draw2DImage(image,position2d<s32>(675,10),rect<s32>(0,0,128,128),0,SColor(255,255,255,255),true);
        smgr->drawAll();
        guienv->drawAll();
        font->draw(L"TEXT :D YAAAAAAAAY!!!!", rect<s32>(300,300,300,50),SColor(255,128,255,128));
 
        driver->endScene();
    }
 
    /*
    After we are finished, we have to delete the Irrlicht Device
    created before with createDevice(). In the Irrlicht Engine,
    you will have to delete all objects you created with a method or
    function which starts with 'create'. The object is simply deleted
    by calling ->drop().
    See the documentation at
    http://irrlicht.sourceforge.net//docu/classirr_1_1IUnknown.html#a3
    for more information.
    */
    device->drop();
 
    return 0;
}
 
 
and for some reason I can't attatch files... so you'll have to live without the font. (Though it was created using the font tool that comes with irrlicht. I used the font Stencil with anti-aliasing and no alpha.
"this is not the bottleneck you are looking for"
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Custom font(s) not working? (XML)

Post by randomMesh »

Try to check if the path of the font is valid.

Code: Select all

 
IGUIFont*font = guienv->getFont("Arial.xml");
if (!font) { printf("Font not found!\n"); device->drop(); return 1; }
 
And please post a MINIMAL compilable example next time. There's no point to post code of an event receiver when you got problems with font loading.
"Whoops..."
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Custom font(s) not working? (XML)

Post by Cube_ »

ah well.. I was a bit lazy with that....
so I posted the whole file :P
and it can find the font.
"this is not the bottleneck you are looking for"
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom font(s) not working? (XML)

Post by CuteAlien »

That code works with the xml font coming with Irrlicht (media/lucida.xml). So can't tell what's wrong without the font-file. You can mail files directly to us - check my sig for my homepage and there you can find my mail-address in contact (sorry, avoiding to post it here due to spam).

edit: I never used the fonttool so far, but I've seen several threads in the past from people figuring out how to export fonts correctly. So please search the forum for other reports on the fonttool, it could be something about the export-settings.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Custom font(s) not working? (XML)

Post by Cube_ »

I'll mail the font to you. I don't see any errors myself, but I might just be overlooking it ^^*
I don't have the font on this computer... I'll mail it to you @ 18.00 GMT+1 (Central Europe Time) or something around that.
"this is not the bottleneck you are looking for"
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom font(s) not working? (XML)

Post by CuteAlien »

Lol at mail arriving at @ 18.00 GMT+1, I'll be watching my mail-inbox with bated breath :-) But please (!) do first what I wrote above - check the forum and look which problems others had - I'm nearly certain this is an export settings thing. And only if that fails send me te font - and if you do so - send me also the font from which you generated it so I can try it myself in the font-tool.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Custom font(s) not working? (XML)

Post by Cube_ »

ok, I'll search.
"this is not the bottleneck you are looking for"
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Custom font(s) not working? (XML)

Post by Cube_ »

can't find anything. mail'd
"this is not the bottleneck you are looking for"
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom font(s) not working? (XML)

Post by CuteAlien »

Your font-files together with your code above work here (after renaming the xml to Arial.xml). Are you sure you have both files in your folder when starting your application?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Custom font(s) not working? (XML)

Post by Cube_ »

yes.
I am positive. could I have called it wrong?
or could my irrlicht dll be corrupt?
"this is not the bottleneck you are looking for"
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom font(s) not working? (XML)

Post by CuteAlien »

I have no idea - I didn't do anything special. Just copied your code from above, fixed the includes (as "q3factory.h" and "sound.h" are not part of this...) and copied the xml and the bmp beside the executable. I used svn trunk - I can maybe try again with 1.7 in the evening.

Just set a breakpoint and check if the font loads.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Custom font(s) not working? (XML)

Post by Cube_ »

I should. and thanks anyway.
and those includes are there for a later use, I just included them so I wouldn't forget.
"this is not the bottleneck you are looking for"
Post Reply