[SDL] loading a surface from resources

Loren Osborn linux_dr at yahoo.com
Sun Jul 28 11:56:01 PDT 2002

--- Nap0cek0 <nap0cek0 at hotmail.com> wrote:
> Hi,
> my problem is that i need to load a bitmap stored in
> the executable
> resources into a SDL_surface
> really I am a newbie of C but theoretically is it
> possible to load the
> bitmap for executable resource with a LoadBitmap,
> assign the bitmap data to
> a FILE variable and then load it with SDL_LoadBMP_RW
> ?

"Resources" are just a windows-ism equivilant to
embedding data into an executable.  The PORTABLE way
to do the same thing is to embed the data in your
program with a shell script similar to the following:

rm -f resource_data.h ; echo '#include
"resource_data.h"' > resource_data.c ; for filename in
*.bmp ; do echo 'extern unsigned char memfile_'`echo
$filename | tr 'A-Z .,/' 'a-z____'`'[];' >>
resource_data.h ; ( echo 'unsigned char memfile_'`echo
$filename | tr 'A-Z .,/' 'a-z____'`'[] =' ; echo '{' ;
od -t x1 -v -w8 $filename | grep ' ' | cut -f2- -d' '
| sed -e 's/^/0x/' -e 's/  */, 0x/g' -e 's/$/,/'; echo
'0x00' ; echo '};' ; echo ' ' ) >> resource_data.c ;

At least this is how you would do it in Unix.  I'm
sure the same script would work under windows using
CygWin... Basically it translates your files into byte
arrays that can be used anywhere in your program
without any windows specific code.  Then you would use
 something like:

SDL_RWops *pMySdlFilePointer =

to access the data as a file.

Hope that helped,


Do You Yahoo!?
Yahoo! Health - Feel better, live better

More information about the SDL mailing list