- Online Community Forums » Programming Questions » [Allegro 5] Loading resources from memory

This thread is locked; no one can reply to it. rss feed Print
[Allegro 5] Loading resources from memory
Member #15,701
August 2014

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
Second in Command
February 2005

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.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Member #15,701
August 2014

Oh thank you ::)

Neil Roy
Member #2,229
April 2002

Go to: