Missing font rendering for font type "image" in Ogre 3.0

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Hotshot5000
OGRE Contributor
OGRE Contributor
Posts: 256
Joined: Thu Oct 14, 2010 12:30 pm
x 64

Missing font rendering for font type "image" in Ogre 3.0

Post by Hotshot5000 »

Just a heads up. I am trying to port an engine that was using a prerelase OgreNext version 2.1 to OgreNext 3.0.
I have a font.fontdef that is using the type image (not "truetype"), and this no longer looks supported.
In OgreFontManager I see:

Code: Select all

StringUtil::toLowerCase( params[1] );
if( params[1] == "truetype" )
{
    pFont->setType( FT_TRUETYPE );
}
else
{
    pFont->setType( FT_IMAGE );
}

but in OgreFont.cpp

Code: Select all

if (mType == FT_TRUETYPE)
{
    createTextureFromFont();
    texLayer = mMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0);
    // Always blend by alpha
    blendByAlpha = true;
}
else
{
    // Manually load since we need to load to get alpha
    mTexture = TextureManager::getSingleton().load(mSource, mGroup, TEX_TYPE_2D, 0);
    blendByAlpha = mTexture->hasAlpha();
    texLayer = mMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(mSource);
}

the else part is missing in 3.0. mTexture is only created when creating texture from ttf. At first glance I thought OgreFont stayed the same as in 2.1 but it looks like I was wrong.

So just a heads up: fonts using images as source are no longer supported.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5496
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1365

Re: Missing font rendering for font type "image" in Ogre 3.0

Post by dark_sylinc »

I don't remember at all why it was marked "TODO". It's possible that:

  1. I didn't want to deal with it.
  2. I didn't have anything to test against (i.e. "is it working ok?").
  3. Functionality that makes it easy now did not exist back then when it was first ported.

From what I can gather in the 2.1 implementation, I think this should work (untested code):

Code: Select all

        if( mType == FT_TRUETYPE )
        {
            createTextureFromFont();
            // Always blend by alpha
            blendByAlpha = true;
        }
        else
        {
            RenderSystem *renderSystem = Root::getSingleton().getRenderSystem();
            TextureGpuManager *textureManager = renderSystem->getTextureGpuManager();
            mTexture = textureManager->createOrRetrieveTexture( mSource, GpuPageOutStrategy::Discard, 0u,
                                                                TextureTypes::Type2D, mGroup );
            mTexture->scheduleTransitionTo( GpuResidency::Resident );
            mTexture->waitForMetadata();
            blendByAlpha = PixelFormatGpuUtils::hasAlpha( mTexture->getPixelFormat() );
        }

Note that there's a few details, e.g. we later call mTexture->removeListener( this ); but this path does not call addListener() since it's not needed. The listener is only needed because the data is created programmatically so if the Texture loses residency, it needs to be filled again. This is not necessary for content loaded from disk.

So if this code works, the removeListener( this ) needs to be avoided or else it will assert or crash.

Hotshot5000
OGRE Contributor
OGRE Contributor
Posts: 256
Joined: Thu Oct 14, 2010 12:30 pm
x 64

Re: Missing font rendering for font type "image" in Ogre 3.0

Post by Hotshot5000 »

Thanks! It's fine in a way the issue signaled that I still used an image for font rendering. Moved to using .ttf so it's not a problem.