First TextAreaOverlayElement added to overlay doesn't appear

Problems building or running the engine, queries about how to use features etc.
Post Reply
BaffledMollusc
Halfling
Posts: 59
Joined: Wed Feb 09, 2005 10:58 am

First TextAreaOverlayElement added to overlay doesn't appear

Post by BaffledMollusc »

Okay, this is a strange problem that's driving me nuts. I can't see what I'm missing.

The problem is, the first container with a TextAreaOverlayElement I try to add to an overlay doesn't appear. Subsequent ones appear fine. A minimal test case is as follows:

Code: Select all

    OverlayContainer* textcontainer1;
    OverlayContainer* textcontainer2;
    TextAreaOverlayElement* textArea1;
    TextAreaOverlayElement* textArea2;

    Ogre::OverlayManager* m_pOverlayManager = Ogre::OverlayManager::getSingletonPtr();
    Ogre::Overlay* pMapOverlay = m_pOverlayManager->create("MapOverlay");

    textcontainer1 = static_cast<OverlayContainer*>(m_pOverlayManager->createOverlayElement("Panel", "TextContainer01"));
    textcontainer1->setMetricsMode(Ogre::GMM_RELATIVE);
    textcontainer1->setDimensions(0.4, 0.4);
    textcontainer1->setPosition(0, 0);

    textcontainer2 = static_cast<OverlayContainer*>(m_pOverlayManager->createOverlayElement("Panel", "TextContainer02"));
    textcontainer2->setMetricsMode(Ogre::GMM_RELATIVE);
    textcontainer2->setDimensions(0.4, 0.4);
    textcontainer2->setPosition(0.5, 0.5);

    textArea1 = static_cast<TextAreaOverlayElement*>(m_pOverlayManager->createOverlayElement("TextArea", "TextArea01"));
    textArea1->setMetricsMode(Ogre::GMM_RELATIVE);
    textArea1->setPosition(0, 0);
    textArea1->setDimensions(0.4, 0.4);
    textArea1->setCaption("Hello1");
    textArea1->setCharHeight(0.05);
    textArea1->setFontName("BlueHighway");

    textArea2 = static_cast<TextAreaOverlayElement*>(m_pOverlayManager->createOverlayElement("TextArea", "TextArea02"));
    textArea2->setMetricsMode(Ogre::GMM_RELATIVE);
    textArea2->setPosition(0, 0);
    textArea2->setDimensions(0.4, 0.4);
    textArea2->setCaption("Hello2");
    textArea2->setCharHeight(0.05);
    textArea2->setFontName("BlueHighway");

    textcontainer1->addChild(textArea1);
    textcontainer2->addChild(textArea2);

    pMapOverlay->add2D(textcontainer2);
    pMapOverlay->add2D(textcontainer1);

    pMapOverlay->show();
When this is run, only the "Hello2" text is visible. If I reverse the order in which I make the pMapOverlay->add2D() calls the "Hello1" text is visible instead. Never both.

If I add yet more text areas they show up fine. It's just the first one I add that doesn't.

If anyone has any suggestions as to what I'm missing I'd be very grateful to hear them!

Edit: More information: Because I can't solve this bug, I use a work around where I add a dummy container with a TextAreaOverlayElement in it to the overlay before I do anything else. It doesn't display, of course, but anything I do subsequently does. The interesting thing is that this work around only succeeds if you set the font type (e.g. setParameter("font_name", "BlueHighway");) of the TextArea.

So the minimum one can do to to get later later text areas to show up is to add a container to the overlay, add a text area to the container, and set the font of the text area. Bizarre. This behaviour occurs if I drop the code into my project or a tutorial project. It also occurs if I use jacmoe's TextRenderer class here: http://www.ogre3d.org/tikiwiki/tiki-ind ... ext+Output. That is, I have to hack that class to add a dummy container with a dummy text area to the overlay before it works.
Kyliroth
Gnoblar
Posts: 2
Joined: Tue Mar 08, 2011 9:30 pm
x 2

Re: First TextAreaOverlayElement added to overlay doesn't ap

Post by Kyliroth »

Hey I've had the same problems. I've found it to to be the font system.

If you put ...
FontManager::getSingletonPtr()->load( "BlueHighway", "Popular" );
... at initialisation it'll load correctly.

It must be something to do when the font is first initialised that it can't be used within the same scope straight away. Obviously swap "BlueHighway" with whatever font you have and "Popular" with wherever bank the font is located.

Hope it helps. It annoyed me cause sometimes it worked but I guess it was cause the font was loaded in somewhere else etc... but it always works now for me.

~ Kyliroth ~

*EDIT: You only need to put that code once during the actual initialisation of the program.
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: First TextAreaOverlayElement added to overlay doesn't ap

Post by loath »

thanks kyliroth!
formula123
Gnoblar
Posts: 7
Joined: Thu Aug 14, 2014 6:23 am

Re: First TextAreaOverlayElement added to overlay doesn't ap

Post by formula123 »

thanks Kyliroth.
It seems the problem have nothing to do with metrics mode.
http://www.ogre3d.org/forums/viewtopic.php?f=4&t=59197
Post Reply