Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm using Allegro 5.0.8 al_draw_text to draw text on a bitmap (backbuffer). However, I've noticed that the first character of the string is always skipped. Moreover, whenever the same character appears in the string, it is skipped again.

For example:

font = al_load_font(path.c_str(), 100, 0);
std::string str = "01230450678";    
al_draw_text(font, color, 100, 100, 0, str.c_str());

Will print "12345678", skipping all occurrences of '0'

I've tried several TTF fonts, which work with other graphic software. I've noticed that this sometimes may or may not happen with the same font, depending only on the text size on screen (font size)

Edit: I've formatted the code and added the arguments I've used to load the font.

Edit2: Here is a complete code to replicate this using Allegro 5.0.8.

This code should print "0123045670890", but, instead, it renders the following image: (Note: I didn't cleared the memory because the error appears before program finishes) enter image description here

//---------------------------------------------------------------------------

#include <string>

#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_opengl.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_primitives.h>
//---------------------------------------------------------------------------


using namespace std;

//---------------------------------------------------------------------------

int main(int argc, char * argv[])
{
    al_init();
    al_install_keyboard();
    al_init_image_addon();
    al_init_primitives_addon();
    al_init_font_addon();
    al_init_ttf_addon();

    al_set_new_display_flags(ALLEGRO_OPENGL);
    ALLEGRO_DISPLAY * mainWindow= al_create_display(1200, 1000);

    ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    string file = al_path_cstr(path, '/');
    file = file + "arial.ttf";
    ALLEGRO_FONT * font = al_load_font(file.c_str(), 50, 0);

    al_set_target_bitmap(al_get_backbuffer(mainWindow));        
    al_draw_filled_rectangle(0, 0, 1200, 1000, al_map_rgb(0,0,0));

    al_draw_text(font, al_map_rgb(255,0,0), 50, 50, 0, "0123045670890");

    al_save_bitmap("d:\\teste.bmp", al_get_backbuffer(mainWindow));

    al_flip_display();

    al_rest(5.0);

    return 0;
}
share|improve this question
1  
Have you tried you using the same command with a C char array ? –  Taigi Jan 7 '13 at 16:00
    
Yes. It's the same. –  Alex Jan 7 '13 at 16:45
2  
Without any other information to go on, that sound like a bug. Not sure what would cause it. You should probably post a small-but-complete example that can be used to reproduce the issue @ allegro.cc/forums/board/allegrodev –  Matthew Jan 8 '13 at 15:40
1  
Does it work if you use memory bitmap for the font? al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP) before loading the font. –  Matthew Jan 8 '13 at 18:01
    
It worked with ALLEGRO_MEMORY_BITMAP. But I haven't found anything related to that in the documentation. Does this means I should always load fonts on regular memory instead of video memory, and may this decrease the performance? Please, put this in an answer so I can close the question, as it fixed the problem. –  Alex Jan 9 '13 at 0:44
show 1 more comment

1 Answer

up vote 3 down vote accepted

It sounds like a bug with caching glyphs. These sorts of glitches generally are only applicable to video memory, so if you switch to a memory bitmap font by calling this before loading the font you can work around the issue:

al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);

You'll need to clear the flags after you load the font, or else all subsequent bitmaps will be software based as well.

However, this is not a good long term solution, as using memory bitmaps may significantly degrade performance.

While the above will probably get you up and running, you should at some point:

  • Upgrade your OpenGL drivers if applicable
  • Try out Allegro 5.1.X, as it may have fixes that have not yet made it to 5.0.X.

If neither of those solve the issue, then you should file a bug report, including the sample source code and details of your OS and video card.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.