![]() |
|
drawing integer values... |
xirb22
Member #13,917
January 2012
|
I want to draw my score to my display, but al_draw_text() only allows the drawing of constant pointer-to-char so it's impossible to draw something like an unsigned int score, even with itoa(). Is there a way to still do this? It's probably something real simple that I'm just overlooking xD TIA |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
A couple minutes of poking around in the examples found this in ex_membmp.c. 1static void print(ALLEGRO_FONT *myfont, char *message, int x, int y)
2{
3 al_draw_text(myfont, al_map_rgb(0, 0, 0), x+2, y+2, 0, message);
4 al_draw_text(myfont, al_map_rgb(255, 255, 255), x, y, 0, message);
5}
6
7 .
8 .
9 .
10 print(font, message, 0, 0);
11 sprintf(second_line, "%.1f FPS", fps);
12 print(font, second_line, 0, al_get_font_line_height(font)+5);
13 .
14 .
15 .
They all watch too much MSNBC... they get ideas. |
xirb22
Member #13,917
January 2012
|
I never really learned C but went straight to C++, so I am a bit confused with the C parts of this code. I am guessing sprintf() is used to print fps into second line and so converts it into a string? If so I'll read up on sprintf() to see how it works so I can use this myself. Thanks for the help bro |
SiegeLord
Member #7,827
October 2006
![]() |
How about al_draw_textf? It'll take out the middle man, allowing you to pass the format string directly to the Allegro function. Look up a printf tutorial on the Internets to figure out how to use format strings (will help with sprintf too, if you end up needing it someday). Also... you can use std::stringstream alongside al_draw_text for a more... C++... solution. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
xirb22
Member #13,917
January 2012
|
al_draw_textf() works perfectly! |
|