TTF to texture generation

Problems building or running the engine, queries about how to use features etc.
Post Reply
fd9_
Halfling
Posts: 64
Joined: Wed Aug 20, 2008 9:20 pm
x 22

TTF to texture generation

Post by fd9_ »

I'm using this code to generate an image from a TTF file: http://www.ogre3d.org/tikiwiki/tiki-ind ... tToTexture

The problem is that the generated texture should be able to fit all of the glyphs on a single 1024x1024 texture, which is what I want. However it's creating a 2048x1024 texture and unnecessarily wasting the majority of the texture space, which is actually empty. If I make the font size smaller, the texture is reduced to a 1024x1024, but the font resolution is not quite large enough for my purposes.

Below is the code that is creating the unnecessarily large (wasted) texture:

Code: Select all

 Ogre::FontPtr font = Ogre::FontManager::getSingletonPtr()->create("MyFont", "General");
    font->setType( Ogre::FT_TRUETYPE );
    font->setSource( "my_font.ttf" );
    font->setTrueTypeSize(15);
    font->setTrueTypeResolution(400); // this should be able to fit on a 1024x1024!
    font->load();
    
    Ogre::String texname = font->getMaterial()->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName();
    
    Ogre::TexturePtr fontTexture = Ogre::TextureManager::getSingleton().getByName(texname);
    Ogre::HardwarePixelBufferSharedPtr fontBuffer = fontTexture->getBuffer();
dbtx
Halfling
Posts: 66
Joined: Tue Nov 01, 2011 9:07 pm
x 10

Re: TTF to texture generation

Post by dbtx »

Just a shot in the dark-- the .ttf may have defined code point ranges where the points have non-zero dimension but no glyph, and the snippet doesn't know the difference so it allocates space in the texture for them anyway. I would examine it with an editor, e.g. FontForge in order to be sure. Then if that's the case and especially if fixing the .ttf isn't viable, I would just modify the snippet to adjust or remove from ranges before iterating over it, or just cherry-pick from it into an empty vector and iterate over that, until the output looks right.
Post Reply