Loading a surface from resources

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 ?

— Nap0cek0 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 ;
done

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 =
SDL_RWFromMem(memfile_my_image_bmp,
sizeof(memfile_my_image_bmp)-1);

to access the data as a file.

Hope that helped,

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