FTGL point size question

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
I'm using FTGL for the text rendering in my GUI, and for my game's HUD. Specifically, I'm using texture fonts and a vanilla ortho projection for the HUD.

The oddity is that I can't figure out how to corrolate FTGL's notion of a point size to the pixels rendered on my screen. For example, if I ask for a 14 pt helvetica, I get a font which when asked for it's ascender, returns 14 -- as I'd expect -- but which when rendered, gives me something between 10 and 12 pixels tall ( due to antialiasing ). Because of this, I can't reliably center text vertically. Oddly, I can center text horizontally...

So, here's a shot of what I'm seeing:
[Image: pointsizes.png]

The bottom red line is the baseline I calculate for centered text if the font really were the 14 pixels tall it reports. The top red line is 14 pixels over the bottom. As you can see, the font isn't nearly 14 pixels tall.

So I have to assume that there's some non-1-to-1 scaling going on here, or that I'm miscalculating something massively.

Here's a bunch of code. First, the button's drawing function:

Code:
void ButtonWidget::display( void )
{
    if ( _font && !_label.empty() )
    {    
        calculateMetrics();
        vec2i origin, outerSize(size()), insetSize;
        
        origin.x = 0;
        origin.y = 0;
        DrawRoundRect( vec2i( 0,0 ), outerSize, DrawRoundRect_MaxCornerRadius, _outlineColor );

        origin.x = Button_Inset;
        origin.y = Button_Inset;
        insetSize.x = outerSize.x - ( 2 * Button_Inset );
        insetSize.y = outerSize.y - ( 2 * Button_Inset );
        
        DrawRoundRect( origin, insetSize,
                       DrawRoundRect_MaxCornerRadius,
                       _trackingMouseDown ? (_hover ? _outlineColor : _color ) : _color );

        vec2i pos(( size().x / 2 ) - ( _labelWidth / 2 ),
                  ( (int)( ceilf( (float)size().y / 2.0f )) - (int) floorf( (float)_labelHeight / 2.0f ) ));

        glBegin( GL_LINES );
        
        glColor3f( 1,0,0 );
        glVertex3f( 0, pos.y, 0 );
        glVertex3f( size().x, pos.y, 0 );

        glVertex3f( 0, pos.y + _labelHeight, 0 );
        glVertex3f( size().x, pos.y + _labelHeight, 0 );
        
        glEnd();
            
        DrawString( _font, _label, pos, _labelColor );
    }
}

Second, the functions to get the sizing for the font -- first, the button's calculateMetrics() code:

Code:
void ButtonWidget::calculateMetrics( void )
{
    if ( _font )
    {
        SizeForString( _font, _label, _labelWidth, _labelHeight );
    }
}

And now the function SizeForString()
Code:
void SizeForString( FTFont *font, std::string str, int &width, int &height )
{
    float llx, lly, llz, urx, ury, urz;

    font->BBox( str.c_str(), llx, lly, llz, urx, ury, urz );
    width = (int) rint( urx - llx );
    height = (int) rint( font->Ascender() );
}

And finally my DrawString function:

Code:
void DrawString( FTFont *font, std::string str, vec2i position, vec4 color )
{
    glPushMatrix();
    glTranslatef( position.x, position.y, 0 );
    glEnable( GL_TEXTURE_2D );
    
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glColor4fv( color.v );
    font->Render( str.c_str() );
    glDisable( GL_TEXTURE_2D );
    glPopMatrix();
}

Is there something I'm missing? This seems so straighforward to me.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #2
For what it's worth, I've come up with a hack that sort of works. I offset the baseline by half of the font's descender. This is brittle, but works so far for me.
Quote this message in a reply
isgoed
Unregistered
 
Post: #3
I have not looked at your code, but I just want to comment that points is not the same as pixels. Using OpenGL or variable resolutions I would stay away from points if I were you.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #4
I'm aware of that, and that's actually the point of my question. How exactly do I convert from FTGL's notion of point size to pixels?

FTGL provides all sorts of nice classes like FTSize but doesn't explain how to use it.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How do I flip upside down fonts in FTGL mr5z 4 898 Mar 3, 2014 03:36 PM
Last Post: JustinFic
  Xcode and FTGL hiddenspring81 7 5,852 Oct 10, 2013 03:00 PM
Last Post: ardowz
  ES 2.0 Point size Mark Levin 1 2,645 Nov 9, 2009 01:46 PM
Last Post: arekkusu
  Anyone run into this problem with FTGL? wadesworld 1 3,012 Apr 21, 2009 02:19 PM
Last Post: Oddity007
  FTGL crash when exiting program Malarkey 8 5,233 Mar 27, 2008 03:33 PM
Last Post: Malarkey