[Allegro 5] Loading resources from memory

Hello everyone!

I have a question for you guys. In the game I am creating, I am using PAK files like those in Quake to store all of my game data into one single file for convinience and security. When the program is furst run it parses the PAK file. It's structure is similar to that of a UNIX file system. But that is not important. The files are stored as is, without compression. I read the files in buffers in memory.

How would I for example load a png image into allegro from a memory buffer (the buffer contains the entire png file, not just the pixel data, ex header and etc...)? ???

PS: Okay I was searching through the allegro documentation and stumbled upon this function:

1ALLEGRO_FILE *al_open_memfile(void *mem, int64_t size, const char *mode)

From what I understand this should create an ALLEGRO_FILE handle to a virtual file in memory. I can then use al_load_bitmap_f with the returned handle to load the bitmap from memory. Is that correct? :-/

Arthur Kalliokoski

You can open a chunk of memory using the al_open_memfile function from the memfile addon. then you can use the al_load_bitmap_f function to load the image from an open file handle.


Oh thank you ::)

Neil Roy

Someone mentioned a solution similar to what you said here.

Thread #614549. Printed from Allegro.cc