Graphics problems in A5
Karadoc ~~

I've just dusted off some old code for the beginnings of a game; but I've found that some of the graphics don't work anymore. In particular, al_draw_text and al_draw_bitmap_region don't seem to do anything. Whereas the drawing primitives, al_draw_filled_rectangle, et al, still seem to work.

Has something changed in allegro which could cause my code to break like this? I'm currently using allegro 5.1.2, and mingw 4.7.0; I think previously I had allegro 5.0.3, or something like that.

It's suspicious that the drawing function which rely on loading data files are the ones that have stopped working... but al_load_font and al_load_bitmap both return non-null values, so I assume the data is still loading ok.

Neil Walker

When I deliver new software or make changes to live, for the next few months any live issue at all, not even remotely related to my changes, partitions blame on me.

I'm sure there's a moral in there somewhere.

Then again, somebody could simply have broken the font system :P

Arthur Kalliokoski

blame on me.

I can't find my Quake disks anywhere, and it's all your fault!

jmasterx

I have been experiencing disappearing glyphs in 5.1.2

I narrowed the revision down to between 15602 and 15608.

Karadoc ~~

So, I'm not the only one seeing this problem. That's a good start.

I just wrote a quick test program. Here's the code:

#SelectExpand
1int main(int argc, char *argv[]) 2{ 3 if (!al_init()) 4 { 5 printf("Could not init Allegro.\n"); 6 return 1; 7 } 8 9 if ( 10 !al_init_primitives_addon() || 11 !al_install_keyboard() || 12 !al_install_mouse() || 13 !al_init_image_addon()) 14 { 15 printf("failed to initialize Allegro components.\n"); 16 return 1; 17 } 18 19 al_init_font_addon(); // void funciton. 20 21 { 22 uint32_t version = al_get_allegro_version(); 23 int major = version >> 24; 24 int minor = (version >> 16) & 255; 25 int revision = (version >> 8) & 255; 26 int release = version & 255; 27 printf("allegro v%d.%d.%d[%d]\n", major, minor, revision, release); 28 } 29 30 printf("gcc v%d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); 31 32 ALLEGRO_FONT *p_font = al_load_font("fixed_font.tga", 0, 0); 33 if (p_font == 0) 34 { 35 printf("fixed_font.tga not found\n"); 36 return 1; 37 } 38 printf("finished loading font.\n"); 39 ALLEGRO_DISPLAY* p_display = al_create_display(400, 400); 40 al_draw_textf(p_font, al_map_rgb_f(1, 1, 1), 200, 200, ALLEGRO_ALIGN_CENTRE, "Hello, World."); 41 al_flip_display(); 42 43 getc(stdin); 44 45 printf("end\n"); 46 return 0; 47}

(getc(stdin) at the bottom basically makes it so that I can't exit; but that's beside the point. I just want to see what's on the screen before the program ends, and I couldn't remember a simple way to do it with allegro functions.)

Anyway, that test program does not print any error message, but it also doesn't display "Hello, World". It only displays a black screen.

fixed_font.tga is a file taken from the allegro examples. Strangely, the examples apparently do work, so I guess I have to take a closer look at my own code. ???

Trent Gamblin

Well, assuming the rest of your code is correct since I only briefly glanced at it, the only "problem" I see is your font is on memory bitmaps, but again, assuming your code is correct it still should display.

Karadoc ~~

Aha!

The text in my example program displays correctly if I create the display before loading the font. So I think we're getting to the heart of the problem now.

@Trent, I hadn't really thought about the memory bitmap vs video bitmap thing. I suppose that creating the display first is all I need to do to fix that 'problem'; is that correct?

[edit]
This business reminds me of this video, which is basically a video about why you shouldn't use global state / singletons, and so on. (this part of the video is the particular bit I was reminded of) -- The fact that allegro did something different when I swapped the order of those apparently unrelated lines of code is an example of how global state can trip people up.

Trent Gamblin

You can create the display later if you set the bitmap flag ALLEGRO_CONVERT_BITMAP before loading/creating the font. (not tested but it theoretically should work the same as any other bitmaps)

Karadoc ~~

Thanks for the tip about the ALLEGRO_CONVERT_BITMAP thing, that might save me from having to rearrange stuff just to get around this problem. (Although, I'm actually intending to rearrange stuff anyway, so I might not end up using it.)

Just to clarify though: the graphics should still work if I load them before creating the display; albeit they will work more slowly. So even though my code was bad, what we're seeing is actually a bug in Allegro. Is this correct?

Thread #610334. Printed from Allegro.cc