Creating bitmap with ALLEGRO_MAG_LINEAR flag before creating display vs after
xsquid

Update: I managed to fix it by doing this instead, to preserve the existing bitmap flags:

#SelectExpand
1al_set_new_bitmap_flags(al_get_new_bitmap_flags() | ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);

So I'm guessing that by doing what what I was doing before, I was loading them as memory bitmaps, and for some reason, creating a display resets that?

----------

I ran into a weird problem today:

  • If I load a bitmap with the ALLEGRO_MAG_LINEAR flag set before creating a display, drawing the bitmap causes the game to run very slow and eat up a lot of CPU.

Example code:

#SelectExpand
1al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR); 2ALLEGRO_BITMAP* bitmap = al_load_bitmap("my_bitmap.png"); 3ALLEGRO_DISPLAY* display = al_create_display(640, 480);

  • If I load the bitmap with the ALLEGRO_MAG_LINEAR flag set after creating a display, it runs perfectly fine.

Example code:

#SelectExpand
1al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR); 2ALLEGRO_DISPLAY* display = al_create_display(640, 480); 3ALLEGRO_BITMAP* bitmap = al_load_bitmap("my_bitmap.png");

Why is this? The documentation doesn't seem to mention anything about it (https://www.allegro.cc/manual/5/al_set_new_bitmap_flags). Is there something else I should be doing?

For the record, I was using the Bitmap tutorial here for testing. I didn't change anything other than adding the pieces of code mentioned above.

(In case it matters, I'm using Allegro 5.2.2.1 on Windows 8.1.)

Elias

You can also use [1] instead, but yes, using the set variant will clear the flag to auto convert memory bitmaps.

Edgar Reynaldo

The problem is that you're loading a bitmap before the display is created. There's no graphics context at that point, so no video bitmaps can be created until there is. Which means you get a memory bitmap which uses memory, CPU, etc...

And Allegro won't auto convert bitmaps for you until you tell it to by calling al_convert_memory_bitmaps.

Edit - see here :

If you create a bitmap without ALLEGRO_MEMORY_BITMAP set but there is no current display, a temporary memory bitmap will be created instead. You can later convert all such bitmap to video bitmap and assign to a display by calling al_convert_memory_bitmaps.

xsquid

The problem is that you're loading a bitmap before the display is created. There's no graphics context at that point, so no video bitmaps can be created until there is. Which means you get a memory bitmap which uses memory, CPU, etc...

And Allegro won't auto convert bitmaps for you until you tell it to by calling al_convert_memory_bitmaps

That makes a lot of sense; I should've realized! I feel like I read this before and then completely forgot about it. Thanks a lot for the helpful responses.

With regards to Elias' response, the ALLEGRO_CONVERT_BITMAP is set by default, and I was clearing it. The ALLEGRO_AUTO_CONVERT_BITMAPS display flag, which is also set by default, will automatically convert memory bitmaps into video bitmaps when the display is created so long as the ALLEGRO_CONVERT_BITMAP flag is set. Does that mean that I don't need to call al_convert_memory_bitmaps as long as I keep these flags enabled? According to the docs, the ALLEGRO_AUTO_CONVERT_BITMAPS flag...

The Manual said:

... causes any existing memory bitmaps with the ALLEGRO_CONVERT_BITMAP flag to be converted to a display bitmap of the newly created display with the option set.

So then, my understanding is that as long as I've got the flags set appropriately I'll never need to call al_convert_memory_bitmaps; this is only for situations where the flags aren't set to have this done automatically. Is this correct?

And as a side-note, would you consider it bad practice to create the bitmaps before creating the display? Is the conversion from memory to video bitmaps super costly?

Elias

Yes, by default all bitmaps will get converted to be used with the first display that is created.

The conversion is costly but has to be done either way because a bitmap loaded from a file always resides in memory at first. So if al_load_bitmap takes time A to load from disk and time B to convert, then if you load your bitmaps after the display you get:

A+B A+B A+B

If you load them before you get:

A+A+A
Create display
B+B+B

In the end the actual game starts at the exact same point in time, after each bitmap was loaded and converted.

Thread #616874. Printed from Allegro.cc