utils: Add helpers for memory bitmaps

This commit is contained in:
Sebastian Krzyszkowiak 2022-07-17 02:03:03 +02:00
parent c36050a920
commit 5ecea298f0
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 22 additions and 0 deletions

View file

@ -207,6 +207,22 @@ SYMBOL_EXPORT ALLEGRO_BITMAP* LoadScaledBitmap(struct Game* game, char* filename
return target;
}
SYMBOL_EXPORT ALLEGRO_BITMAP* LoadMemoryBitmap(const char* filename) {
int flags = al_get_new_bitmap_flags();
al_set_new_bitmap_flags((flags | ALLEGRO_MEMORY_BITMAP) & ~(ALLEGRO_VIDEO_BITMAP | ALLEGRO_CONVERT_BITMAP));
ALLEGRO_BITMAP* bitmap = al_load_bitmap(filename);
al_set_new_bitmap_flags(flags);
return bitmap;
}
SYMBOL_EXPORT ALLEGRO_BITMAP* CreateMemoryBitmap(int width, int height) {
int flags = al_get_new_bitmap_flags();
al_set_new_bitmap_flags((flags | ALLEGRO_MEMORY_BITMAP) & ~(ALLEGRO_VIDEO_BITMAP | ALLEGRO_CONVERT_BITMAP));
ALLEGRO_BITMAP* bitmap = al_create_bitmap(width, height);
al_set_new_bitmap_flags(flags);
return bitmap;
}
SYMBOL_EXPORT void FatalErrorWithContext(struct Game* game, int line, const char* file, const char* func, bool exit, char* format, ...) {
char text[1024] = {0};
PrintConsole(game, "Fatal Error, displaying Blue Screen of Derp...");

View file

@ -52,6 +52,12 @@ void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height);
/*! \brief Loads bitmap into memory and scales it with software linear filtering. */
ALLEGRO_BITMAP* LoadScaledBitmap(struct Game* game, char* filename, int width, int height);
/*! \brief Creates a memory bitmap loaded from a file. */
ALLEGRO_BITMAP* LoadMemoryBitmap(const char* filename);
/*! \brief Creates a memory bitmap with specified dimensions. */
ALLEGRO_BITMAP* CreateMemoryBitmap(int width, int height);
/*! \brief Finds the path for data file. Returns NULL when the file can't be found, or ephemeral string otherwise. */
const char* FindDataFilePath(struct Game* game, const char* filename);
/*! \brief Finds the path for data file. Triggers BSOD and quits when the file can't be found, returns ephemeral string otherwise. */