I've been struggling with solving an issue regarding Overlays (I know its old but I don't have a choice for now).
The problem arises when I try to calculate the size of a string, when using a specific font, to align the string.
The specific line is this:
Code: Select all
Ogre::String text = // Some text
float fontHeight = // Some non zero/negative float
...
// for each character in the string
float characterWidth = font->getGlyphAspectRatio(static_cast<Ogre::Font::CodePoint>(text[i]))*fontHeight;
So looking into the code I find:
Code: Select all
/** Gets the aspect ratio (width / height) of this character. */
inline Real getGlyphAspectRatio(CodePoint id) const
{
CodePointMap::const_iterator i = mCodePointMap.find(id);
if (i != mCodePointMap.end())
{
return i->second.aspectRatio;
}
else
{
return 1.0;
}
}
Font arial using texture size 4096x2048
Info: Freetype returned null for character 32 in font arial
Info: Freetype returned null for character 160 in font arial
Texture: arialTexture: Loading 1 faces(PF_RG8,4096x2048x1) Internal format is PF_RG8,4096x2048x1.
So it seems that the first time I attempt to use the Font it has not finished/loaded properly (since it returns null for some characters) but then after that works fine?
Am I loading the font incorrectly?
Code: Select all
// Font stuff now that OverlayManager is created
Ogre::FontManager* fontManager = Ogre::FontManager::getSingletonPtr();
Ogre::FontPtr fontPtr = fontManager->create("arial", "General");
Ogre::Font* font = fontPtr.getPointer();
font->setType(Ogre::FT_TRUETYPE);
font->setSource(fontFolderPath + "/arial.ttf");
font->setTrueTypeSize(72);
font->setTrueTypeResolution(128);
font->addCodePointRange(Ogre::Font::CodePointRange(0, 255));
}
Looked for this issue on the forum, the log message seems to be quite common but could not find an example of this specific issue.
Thanks for reading!