Problem displaying text in overlay

Problems building or running the engine, queries about how to use features etc.
Post Reply
clovekx
Gnoblar
Posts: 4
Joined: Fri May 28, 2010 11:54 pm

Problem displaying text in overlay

Post by clovekx »

I am not able to make text rendering work. I use the following code to create an overlay:

Code: Select all

OverlayManager &overlayManager = OverlayManager::getSingleton();
	Overlay *stats = overlayManager.create("Stats Overlay");
	
	OverlayContainer *panel = (OverlayContainer*)(overlayManager.createOverlayElement("Panel", "Stats Panel"));
	panel->setMetricsMode(GMM_PIXELS);
	panel->setPosition(100, 100);
	panel->setDimensions(200, 200);
	panel->setMaterialName("GuiMaterial");

	TextAreaOverlayElement* textArea = (TextAreaOverlayElement*)(overlayManager.createOverlayElement("TextArea", "SomeText"));
	textArea->setMetricsMode(Ogre::GMM_PIXELS);
	textArea->setPosition(0, 0);
	textArea->setDimensions(100, 100);
	textArea->setCharHeight(16);
	textArea->setColour(ColourValue(1.0, 0.2, 0.2));
	textArea->setFontName("BlueHighway");
	textArea->setCaption("AAAAA !.\nBBB");

	panel->addChild(textArea);
	stats->add2D(panel);

	stats->show();
The panel displays, but there is no text. Font is probably correct, because in log there is:

Code: Select all

01:12:59: Font BlueHighwayusing texture size 512x256
01:12:59: Texture: BlueHighwayTexture: Loading 1 faces(PF_BYTE_LA,512x256x1) with 0 generated mipmaps from Image. Internal format is PF_BYTE_LA,512x256x1.
The font script contains:

Code: Select all

BlueHighway
{
	type truetype
	source bluehigh.ttf
	size 16
	resolution 96
	code_points 33-126
}
I use MSVC 2010 on WXP and OpenGL renderer. What could be a problem?

EDIT: I have noticed that when I resize the window, the text appears. I use my own render loop. Could that be a problem?

Code: Select all

	bool done = false;	
	while(!done){
		// run the message pump
		Ogre::WindowEventUtilities::messagePump();

		m_root->renderOneFrame();

		m_keyboard->capture();
		done = m_keyboard->isKeyDown(OIS::KC_ESCAPE) || m_renderWindow->isClosed();
	}
clovekx
Gnoblar
Posts: 4
Joined: Fri May 28, 2010 11:54 pm

Re: Problem displaying text in overlay

Post by clovekx »

It seems like a bug to me. Should I report it somewhere?
sarcacid
Gnoblar
Posts: 3
Joined: Tue Mar 02, 2010 12:32 am

Re: Problem displaying text in overlay

Post by sarcacid »

Did you ever solve the problem? I'm experiencing the same thing... I use OGRE's render loop though.
outburstx
Gnoblar
Posts: 6
Joined: Wed May 05, 2010 5:54 am

Re: Problem displaying text in overlay

Post by outburstx »

I am experiencing the same problem on Fedora 12 64-bit w/ OpenGL, using Ogre's render loop.
Text appears when I resize.
clovekx
Gnoblar
Posts: 4
Joined: Fri May 28, 2010 11:54 pm

Re: Problem displaying text in overlay

Post by clovekx »

I have only found a workaround - not a real solution:
1. Set the overlay as usually
2. Call Root::renderOneFrame()
3. Set the caption
Stickymango
Hobgoblin
Posts: 540
Joined: Wed Nov 17, 2004 4:36 pm
Location: Middlesbrough, England

Re: Problem displaying text in overlay

Post by Stickymango »

Yep, I can confirm this too, weird :?
IceGreek
Gnoblar
Posts: 1
Joined: Fri Jul 23, 2010 8:25 pm

Re: Problem displaying text in overlay

Post by IceGreek »

I have the same problem. :(
Text displaying then I call method getMaterial() on TextAreaOverlayElement object before rendering.
jtpsoft
Greenskin
Posts: 115
Joined: Wed Feb 01, 2006 1:22 pm

Re: Problem displaying text in overlay

Post by jtpsoft »

Isn't there a solution for this issue yet? I run into the same problem without find a solution,even with the workaround!

Thx a lot
nkligang
Kobold
Posts: 35
Joined: Wed Aug 18, 2010 9:14 am

Re: Problem displaying text in overlay

Post by nkligang »

I have the same problem in Mac OS X.
Stickymango
Hobgoblin
Posts: 540
Joined: Wed Nov 17, 2004 4:36 pm
Location: Middlesbrough, England

Re: Problem displaying text in overlay

Post by Stickymango »

I've traced the bug:

previously in TextAreaOverlayElement:

Code: Select all

 void TextAreaOverlayElement::setFontName( const String& font )
    {
        mpFont = FontManager::getSingleton().getByName( font );
        if (mpFont.isNull())
            OGRE_EXCEPT( Exception::ERR_ITEM_NOT_FOUND, "Could not find font " + font,
                "TextAreaOverlayElement::setFontName" );

        mpFont->load();
        mpMaterial = mpFont->getMaterial();
        mpMaterial->setDepthCheckEnabled(false);
        mpMaterial->setLightingEnabled(false);

        mGeomPositionsOutOfDate = true;
        mGeomUVsOutOfDate = true;
    }
But now the font load code has been moved to getMaterial():

Code: Select all

   const MaterialPtr& TextAreaOverlayElement::getMaterial(void) const
    {
        // On-demand load
        // Moved from setFontName to avoid issues with background parsing of scripts
        if (mpMaterial.isNull() && !mpFont.isNull())
        {
            mpFont->load();
            // Ugly hack, but we need to override for lazy-load
            *const_cast<MaterialPtr*>(&mpMaterial) = mpFont->getMaterial();
            mpMaterial->setDepthCheckEnabled(false);
            mpMaterial->setLightingEnabled(false);
        }
        return mpMaterial;
    }
This causes the font not to be rendered the first time its used. Reverting back to the original code fixes the issue but I gather that causes issues with parsing, I haven't worked out where is the best place to insert this code yet, so I thought I'd throw it open to one of the devs who have a better understanding how the system works :wink:
Stickymango
Hobgoblin
Posts: 540
Joined: Wed Nov 17, 2004 4:36 pm
Location: Middlesbrough, England

Re: Problem displaying text in overlay

Post by Stickymango »

FYI,

I moved the code to updatePositionGeometry():

Code: Select all

 void TextAreaOverlayElement::updatePositionGeometry()
    {
        float *pVert;

        if (mpFont.isNull())
        {
            // not initialised yet, probably due to the order of creation in a template
            return;
        }

        // On-demand load
        // Moved from setFontName to avoid issues with background parsing of scripts
        if (mpMaterial.isNull())
        {
            mpFont->load();
            // Ugly hack, but we need to override for lazy-load
            *const_cast<MaterialPtr*>(&mpMaterial) = mpFont->getMaterial();
            mpMaterial->setDepthCheckEnabled(false);
            mpMaterial->setLightingEnabled(false);
        }
And it fixes the issue, but I doubt its the most suitable place and if there is any affect to the background loading process...
gabdab
Halfling
Posts: 60
Joined: Mon Jun 09, 2003 8:09 pm

Re: Problem displaying text in overlay

Post by gabdab »

I hope you solved it allready.
I guess problem is related to overlays position being relative to screensize ,es:
screensize: 800x600
overlay position (text position): 400,200
x: 400/800 = 0.5
y: 200/600 = ~0,3

text position : (0.5,0.3)
Post Reply