Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » A question regarding how Allegro draws text

This thread is locked; no one can reply to it. rss feed Print
A question regarding how Allegro draws text
Eric Johnson
Member #14,841
January 2013
avatar

Something I observed today: al_draw_text does not draw text where I expected it to. I wanted to draw text snug to the top left corner of the display, but the y axis is not touching the top as I thought it would.

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_font.h> 3#include <allegro5/allegro_ttf.h> 4 5int main(void) { 6 7 al_init(); 8 9 al_init_font_addon(); 10 al_init_ttf_addon(); 11 12 ALLEGRO_DISPLAY *display = al_create_display(768, 448); 13 14 ALLEGRO_FONT *font = al_load_ttf_font("arial_black.ttf", 80, 0); 15 16 al_clear_to_color(al_map_rgb(255, 255, 255)); 17 18 al_draw_text(font, al_map_rgb(0, 0, 0), 0, 0, 0, "This is a test!"); 19 20 al_flip_display(); 21 22 al_rest(5); 23 24 al_destroy_font(font); 25 26 al_destroy_display(display); 27 28 return 0; 29}

See the attached file for a screenshot of what happened and then what I expected to happen (edited in GIMP).

Is this the result of extra space in the font itself? Thanks.

</stupidquestion>

Todd Cope
Member #998
November 2000
avatar

You should use al_get_text_dimensions() if you need exact text placement. You just subtract the x and y values returned by al_get_text_dimensions() from your target coordinates.

Eric Johnson
Member #14,841
January 2013
avatar

Go to: