Mmm interesting what you said about zipfiles…
But my goal is not to make everything available from one binary…
See, I am writing a library to simplify using SDL (I know it s already
simple, but still…) . As an example one call to my lib and you can create
a window with basic event handling.
To achieve this kind of goal you need some default behaviour and default
data.
At the moment my library actually depends on only one little image file :
the icon for the window.
I dont want the build to mess around with this file, and I dont want users
to have to put the file in the correct place before using the library…
Thats why embedding the file in the source code looks the good solution to
me.
I was able to get the raw code of the whole file but using it is not really
simple.
I think I am gonna have a look at the RWOps to use them to read my data from
memory…
Thanks a lot all for your help.
2006/1/25, Ryan C. Gordon :>
I would like to store the image somehow in the source code
Is the goal in doing this to make everything available from one binary,
or is it just to make it so you don’t have to do file i/o and allocation
to get at the data?
I’d be inclined to avoid this tactic, but you COULD write a small
program to convert a file into a C array:
/* This code hasn’t even been compiled, let alone debugged. */
int main(int argc, char **argv)
{
int ch;
printf("unsigned char myfile[] = {\n");
while ((ch = fgetc()) != EOF)
printf("0x%X,\n", ch);
printf("};\n\n");
return 0;
}
…then run it as “convertdata < myfile.bmp > myfile.c”
Obviously, that can be cleaned up a little.
However, if you don’t mind jumping through some hoops and really just
wanted all your data to be contained in one file with your binary, you
can save on ugliness and static memory usage by putting a bunch of files
in a zipfile and attaching it to the end of the binary…this works on
at least Windows and Linux, maybe Mac OS, too. Zipfiles store their
table of contents at the end of the file, so this is how self-extracting
.EXE files get away with it.
So now the pipeline looks like:
- Build your program in myprogram
- Build your data in mydata.zip
- cat myprogram mydata.zip > finalprogramfile
Verify it works:
- unzip -v finalprogramfile
Now run the program and have it open itself as a zipfile at runtime to
access the data.
“have it open itself as a zipfile at runtime” is left as an exercise to
the reader. This may be overkill, depending on your needs.
–ryan.
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl