Cinder
Cinder copied to clipboard
linux: TextureFont vertical alignment off
This is affecting any platforms using the FreeType impl of ci::gl::TextureFont
. You can see how the vertical alignment is different in the TextureFont sample by adding these two lines here:
gl::color( 1, 0, 0 );
gl::drawStrokedRect( boundsRect );
Compare windows desktop:
to Ubuntu desktop:
The issue becomes more apparent with a more involved interface, such as the _audio/DeviceTest. Windows desktop:
and Ubuntu Desktop:
This also affects Raspberry Pi and TK1 platforms, as initially reported in #1844.
Has anyone made any progress with this issue? cc @richardeakin
It's a longstanding issue that awaits a complete text rewrite, there are quite a few posts about that but no ETA.. For the time being there are also various other text wrappers available.
Thanks @richardeakin ! I appreciate your looking into this. Not sure that I have the bandwidth to dive deep and pull all the threads together at the moment. But might try at some point if no one beats me to it :)
Ok, I'm not all the way there, but there's a problem here: https://github.com/cinder/Cinder/blob/ef8254525eed9e2589b6bf1b19e2205f148c5de8/src/cinder/gl/TextureFont.cpp#L761
Specifically, glyphInfoIt->second.mTexCoords.getSize()
gives the wrong values.
I haven't traced through the logic yet, but it's set here:
https://github.com/cinder/Cinder/blob/ef8254525eed9e2589b6bf1b19e2205f148c5de8/src/cinder/gl/TextureFont.cpp#L382
From my limited tests and use-cases, the output looks right to me if I replace L761 with:
result += glyphInfoIt->second.mOriginOffset + getFont().getGlyphBoundingBox( glyphMeasures.back().first ).getSize();
Oh, almost forgot to mention the offset itself:
drawString()
's vertical alignment is off by the ascent.
A call to:
textureFont->drawString( str, basePos );
is replaced by:
textureFont->drawString( str, basePos + vec2( 0, textureFont->getAscent() ) );
I haven't gone very deep into understanding this implementation and I know it's due for a big rewrite, so I defer to you @richardeakin as to whether this is worth taking any further. Certainly this is at best a hotfix.
I think if you find a fix it's worth posting, but as mentioned a complete overhaul is imminent (though pending a few people's work schedules) - if you can manage it we can probably merge, otherwise I'd suggest looking at an alternative text rendering solution when the layout gets particular such as Potion / Cinder-Text.