Search code examples
c++allegro5

Allegro 5 al_draw_textf()


I have been looking how to draw string on the screen using Allergo 5 and knew about al_draw-textf() which was said to work like printf() in stdio.h . So when I want to print a string on console window I write printf("%s" , string_name); But when I write this

al_draw_textf(font , al_map_rgb(255 , 255 , 0) , 250 , 250 , ALLEGRO_ALIGN_LEFT , "%s" , num);

there is nothing written on the display . When I change the %s to %d and the num variable to an integer it draws the value of the num correctly . Am I doing something not correctly or this function is only used to draw integer variables ?


Solution

  • If all you want to do is draw a constant string without formatting, just use:

    void al_draw_text(const ALLEGRO_FONT *font,
       ALLEGRO_COLOR color, float x, float y, int flags,
       char const *text)
    

    Although what you are doing should still work, so if the above doesn't help, you'll need to post more code.