- Online Community Forums » Programming Questions » Scaled font print call?

This thread is locked; no one can reply to it. rss feed Print
Scaled font print call?
Member #16,156
January 2016

The game that I am trying to create scales all my images to fit the middle of the screen. Thus if the game is 640 by 480 it will scale it on a computer screen that is 1080 * 720 and so forth.

When I print a scaled bitmap the coordinates change to negative coordinate (I don't know why but I have adjusted to that)

The problem I am running into is that for bitmaps there is a function call called
- al_draw_scaled_bitmap()
But for fonts I don't know if there exist such a function call and if not how do I scale it so that it prints on the right coordinate for the screen.

Here is an example
- al_draw_scaled_bitmap(mapImagePlain, -row * 32, -column * 24, screenWidth, screenHeight, scaleX, scaleY, scaleW, scaleH, 0);

  • where the xPosition and yPosition are both negative but for this call:

- al_draw_text(font, al_map_rgb(red, green, blue), xPosition, yPosition, NULL, text);

  • where the xPosition and yPosition are positive and its coordinates deals with the actual screen size

If anyone knows a solution or has advice it would be much appreciated thank you

Mark Oates
Member #1,146
March 2001

Yes, there are no functions to scale fonts.

The current way to draw a scaled font is to draw your text to a separate ALLEGRO_BITMAP. Then, draw a scaled bitmap.

It might be something like this:

1ALLEGRO_BITMAP *create_text_render(ALLEGRO_FONT *font, ALLEGRO_COLOR color, const char *text) 2{ 3 ALLEGRO_STATE previous_state; 4 al_store_state(&previous_state, ALLEGRO_STATE_TARGET_BITMAP); 5 6 int bitmap_w = al_get_text_width(font, text); 7 int bitmap_h = al_get_font_line_height(font); 8 ALLEGRO_BITMAP *text_render = al_create_bitmap(bitmap_w, bitmap_h); 9 10 al_set_target_bitmap(text_render); 11 al_clear_to_color(al_map_rgba_f(0.0, 0.0, 0.0, 0.0)); 12 13 al_draw_text(font, color, 0, 0, NULL, text); 14 15 al_restore_state(&previous_state); 16 return text_render; 17}

^ This is not tested; there may be typos. Here's how it's done in AllegroFlare.

Member #16,156
January 2016

Thank You! I'll give that a try and I'll let you know how that goes.

Chris Katko
Member #1,881
January 2002

If the fonts are TTF, can't you just increase the font point size?

Scaling small text to HD is going to be very ugly.

“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Go to: