Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » al_draw_text(...) not accurate

This thread is locked; no one can reply to it. rss feed Print
al_draw_text(...) not accurate
fallenlight12
Member #14,669
October 2012

The problem I'm having is... Well, here's the code:

#SelectExpand
1ALLEGRO_FONT *font = al_load_ttf_font("octovill.ttf",30,0 ); 2if (!font){ 3 LOG("...could not load 'octovill.ttf'.\nEnd Program.", true); 4 kill_allegro(); 5 return -1; 6} 7int txtx, txty, txtw, txth; 8al_get_text_dimensions(font, "Press ESC to exit program.", &txtx, &txty, &txtw, &txth); 9al_draw_text(font, al_map_rgb(190,225,190), 0, 0, 0, "Press ESC to exit program.");

The text should appear at 0,0 at the top-left of screen. It does. Its x-position is accurate, but its y-position is +2 in error.

Additionally, al_get_text_dimensions(...) returns an erroneous y offset and a height that's greater than what it should be. The width and x offset it returns are accurate.

The reason I have to come here and ask is because if I don't figure out why it does this then I'll have to write some code to examine the font myself and get the correct x/y offset/width/height for each font type.

If that wasn't enough, I also have to report that when I use ALLEGRO_ALIGN_CENTRE in al_draw_text(...) it centers correctly horizontally but not vertically. In fact, I don't think it even tries to center vertically.

So there appears to be some screwy vertical/y-axis bugs.

On the plus-side, if I can't fix this then I can just convert some win32 code I wrote over to allegro - all i gotta do is replace gdi calls with allegro. (I was loading my fonts from bitmap files.)

I'm using Allegro 5.0.7 binaries.

Peter Wang
Member #23
April 2000

Don't know about the y offset. Perhaps it is part of the font?

ALLEGRO_ALIGN_LEFT/CENTRE/RIGHT only align horizontally.

Kris Asick
Member #1,424
July 2001

Most TTF fonts are not pixel-perfect. You'll almost certainly have to adjust your coordinates to take into account the nuances of each font you use. :P

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Elias
Member #358
May 2000

Do you have a screenshot and is that .ttf available somewhere?

--
"Either help out or stop whining" - Evert

Go to: