Compiling Files into SDL Application

Using a Mac, to add a file to the SDL program (sound file or image) I (so far) have to put the files into the same folder as the final SDL built application. Is there a simple way to compile these files into the program itself, so that when I move the program around, I don’t have to make sure to move all the images/sounds with it?

I made an app using quite a few sound files, and plan to add images to it, and I already tried dragging the sound files into the Xcode project, and into subfolders like Sources and Resources. Nothing seems to work - I still am required to place the extra files in the same folder as the SDL Application.

Could anyone help?

-Jesse O.

Check out this page –
http://www.noquarterarcade.com/xcode-sdl-development-setup

It describes where to put the image and sound files for Debug and
Release builds with Xcode and there is a modified SDLMain.m so you can
put the files in the .app bundle for distribution.

This is for SDL 1.2.

Todd SteinackleOn Sat, Jan 30, 2010 at 11:27 AM, jesseoffy wrote:

Using a Mac, to add a file to the SDL program (sound file or image) I (so
far) have to put the files into the same folder as the final SDL built
application. Is there a simple way to compile these files into the program
itself, so that when I move the program around, I don’t have to make sure to
move all the images/sounds with it?

I made an app using quite a few sound files, and plan to add images to it,
and I already tried dragging the sound files into the Xcode project, and
into subfolders like Sources and Resources. Nothing seems to work - I still
am required to place the extra files in the same folder as the SDL
Application.

Could anyone help?

-Jesse O.

Hi,

In case you want them directly in an executable, you can convert them to .h files and include them in your project. Basically the file data will be defined as an array of characters. I think you can Google some utilities that will do this for you.

However this is only efficient if you are using data directly without any conversion. For example keeping a PNG file inside your executable is a very bad decision. It will occupy memory in compressed (PNG) form, then you have to decode it to let’s say a SDL_Surface and that will occupy memory as well.

PavelOn 30.1.2010, at 17:27, jesseoffy wrote:

Using a Mac, to add a file to the SDL program (sound file or image) I (so far) have to put the files into the same folder as the final SDL built application. Is there a simple way to compile these files into the program itself, so that when I move the program around, I don’t have to make sure to move all the images/sounds with it?

I made an app using quite a few sound files, and plan to add images to it, and I already tried dragging the sound files into the Xcode project, and into subfolders like Sources and Resources. Nothing seems to work - I still am required to place the extra files in the same folder as the SDL Application.

Could anyone help?

-Jesse O.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi

I don’t know about Mac but I used MoleBox to compress my resources and exe into one executable package. It’s a great program but does cost!

Ed________________________________
From: kanzels@gmail.com (Pavel Kanzelsberger)
To: sdl at lists.libsdl.org
Sent: Sat, 30 January, 2010 19:06:06
Subject: Re: [SDL] Compiling Files into SDL Application

Hi,

In case you want them directly in an executable, you can convert them to .h files and include them in your project. Basically the file data will be defined as an array of characters. I think you can Google some utilities that will do this for you.

However this is only efficient if you are using data directly without any conversion. For example keeping a PNG file inside your executable is a very bad decision. It will occupy memory in compressed (PNG) form, then you have to decode it to let’s say a SDL_Surface and that will occupy memory as well.

Pavel

On 30.1.2010, at 17:27, jesseoffy wrote:

Using a Mac, to add a file to the SDL program (sound file or image) I (so far) have to put the files into the same folder as the final SDL built application. Is there a simple way to compile these files into the program itself, so that when I move the program around, I don’t have to make sure to move all the images/sounds with it?

I made an app using quite a few sound files, and plan to add images to it, and I already tried dragging the sound files into the Xcode project, and into subfolders like Sources and Resources. Nothing seems to work - I still am required to place the extra files in the same folder as the SDL Application.

Could anyone help?

-Jesse O._______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

@toddsteinackle: That link is talking about exactly what I need, though I can’t find where to edit the SDLmain.m I downloaded his link on the bottom but it seems to be the exact same. I’ll give it a try though, in case I missed something in there.

Pavel Kanzelsberger wrote:

In case you want them directly in an executable, you can convert them to
.h files and include them in your project.
[snip]
However this is only efficient if you are using data directly without
any conversion. For example keeping a PNG file inside your executable is
a very bad decision. It will occupy memory in compressed (PNG) form,
then you have to decode it to let’s say a SDL_Surface and that will
occupy memory as well.

It’s not that bad, right? With virtual memory and memory mapping
of files, you don’t really occupy actual RAM for the original data…–
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

Hm,

what you want are resource files. Dunno know if they exist on Mac OS or
how your compiler support them.
What about a small tool, which generates a c file with
struct mycompiledinfile
{
int size;
char *data;
}

and a global static variable of this type with an escaped char string
for the file content for each file you want in your app. then you could
use a SDL_rwops on this memory location.Am 30.01.2010 20:40, schrieb KHMan:

Pavel Kanzelsberger wrote:

In case you want them directly in an executable, you can convert them
to .h files and include them in your project. [snip]
However this is only efficient if you are using data directly without
any conversion. For example keeping a PNG file inside your executable
is a very bad decision. It will occupy memory in compressed (PNG)
form, then you have to decode it to let’s say a SDL_Surface and that
will occupy memory as well.

It’s not that bad, right? With virtual memory and memory mapping of
files, you don’t really occupy actual RAM for the original data…


Christoph Nelles

E-Mail : @Christoph_Nelles
Jabber : eazrael at evilazrael.net ICQ : 78819723

PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt

@toddsteinackle: That link is talking about exactly what I need, though I
can’t find where to edit the SDLmain.m I downloaded his link on the bottom
but it seems to be the exact same. I’ll give it a try though, in case I
missed something in there.

You don’t have to edit it. The changes are in this function

  • (void) setupWorkingDirectory:(BOOL)shouldChdir

Just replace the SDLmain.m in Xcode when you do your release build and
then you can put your image/sound files in the Contents/Resources
folder within the .app bundle.

Todd Steinackle
http://www.noquarterarcade.com/On Sat, Jan 30, 2010 at 2:38 PM, jesseoffy wrote:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ok, thanks for the help!

Ok, but how that C-header or C-source is used in the code,i.e. blitted as a surface?

Fore example,I have this source in the class.cpp:

static const unsigned short m_pic_bmp[] = {0x8e00b4, 0x4c008a, 0xa756c5, 0xe6adee,
0x963eb9, 0x580090, 0x000000, 0x570090, 0x9740ba, 0xe7b5ee, 0xd89ae5, 0x51008e, 0x000000,
0x000000, 0x000000, 0x000000, 0x7e2daa, 0xd999e5, 0xfed0ff, 0xe7bdf8, 0x9541bb, 0x440082,
0xaa57c6, 0xf6ccff, 0xefc7fe, 0xefb9f4, 0xac5dc8, 0x000000, 0x000000, 0x000000, 0x000000,

0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x65069a, 0x9842bb, 0x963eb9,
0x4f008c, 0x000000, 0x000011, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000057, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000};

defined as a member variable of some class.How it is applied on the screen with SDL_BlitSurface?

dekyco

Hi,

use http://sdl.beuc.net/sdl.wiki/SDL_RWFromMem . There are some links
tutorials at the end of this page:
http://sdl.beuc.net/sdl.wiki/SDL_RWopsAm 01.02.2010 14:34, schrieb dekyco:

Ok, but how that C-header or C-source is used in the code,i.e. blitted
as a surface?

Fore example,I have this source in the class.cpp:

static const unsigned short m_pic_bmp[] = {0x8e00b4, 0x4c008a, 0xa756c5,
0xe6adee,
0x963eb9, 0x580090, 0x000000, 0x570090, 0x9740ba, 0xe7b5ee, 0xd89ae5,
0x51008e, 0x000000,
0x000000, 0x000000, 0x000000, 0x7e2daa, 0xd999e5, 0xfed0ff, 0xe7bdf8,
0x9541bb, 0x440082,
0xaa57c6, 0xf6ccff, 0xefc7fe, 0xefb9f4, 0xac5dc8, 0x000000, 0x000000,
0x000000, 0x000000,

0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x65069a,
0x9842bb, 0x963eb9,
0x4f008c, 0x000000, 0x000011, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000057, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000};

defined as a member variable of some class.How it is applied on the
screen with SDL_BlitSurface?

dekyco


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Christoph Nelles

E-Mail : @Christoph_Nelles
Jabber : eazrael at evilazrael.net ICQ : 78819723

PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt

Thank you very much,this is what I wanted.Situation is like this: I have used bmp2c utility to make C-

source file out of bitmap file (.bmp),so ended up with array m_pic_bmp[] like above.Now that source

bitmap.c is added to project and compiled like .obj file.

Now the question is how can I access this resource which is now compiled in program?

Hi,

i think you need a header with something like
extern unsigned short *m_pic_bmp;

This should be the pointer to the data you need to pass to the
SDL_RWFromConstMem() function. You probably need the size of the data, too.Am 01.02.2010 16:35, schrieb dekyco:

Thank you very much,this is what I wanted.Situation is like this: I have
used bmp2c utility to make C-

source file out of bitmap file (.bmp),so ended up with array m_pic_bmp[]
like above.Now that source

bitmap.c is added to project and compiled like .obj file.

Now the question is how can I access this resource which is now compiled
in program?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Christoph Nelles

E-Mail : @Christoph_Nelles
Jabber : eazrael at evilazrael.net ICQ : 78819723

PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt

No luck so far…

Just to be clear here is what I did:

  1. source file bitmap.c which contains:

#define x_pic_bmp 15;//width of the picture
#define y_pic_bmp 15;//height of the picture

static const unsigned short pic_bmp[] = {0x8e00b4, 0x4c008a, 0xa756c5, 0xe6adee,
0x963eb9, 0x580090, 0x000000, 0x570090, 0x9740ba, 0xe7b5ee, 0xd89ae5, 0x51008e, 0x000000,
0x000000, 0x000000, 0x000000, 0x7e2daa, 0xd999e5, 0xfed0ff, 0xe7bdf8, 0x9541bb,

0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000057, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000};

is compiled in VC++ into .obj file.

  1. some variables are defined in Globals.cpp: unsigned short *pic_bmp;

    and in Globals.h : extern unsigned short *pic_bmp;

  2. where picture data is to be loaded,it is called like this:

    SDL_RWops *rw;

    rw = SDL_RWFromConstMem(pic_bmp, sizeof(pic_bmp));

    //load it into member variable of type SDL_Surface*:

    m_pic = SDL_LoadBMP_RW(rw, 0);

  3. which compiles fine, but crashes on run.

Any ideas on this?

dekyco

Hi,On Tue, 02 Feb 2010 04:19:14 -0800, “dekyco” wrote:

  1. where picture data is to be loaded,it is called like this:

    SDL_RWops *rw;

    rw = SDL_RWFromConstMem(pic_bmp, sizeof(pic_bmp));

    //load it into member variable of type SDL_Surface*:

    m_pic = SDL_LoadBMP_RW(rw, 0);

  2. which compiles fine, but crashes on run.
    Any ideas on this?

It’s just a guess, i can’t try it now. Please insert
printf(“Size: %d\n”, sizeof(pic_bmp));
fflush (stdout);
(or std::cout << "Size: " << sizeof(pic_bmp) << std::endl << std::flush;
before rw = SDL_RWFromConstMem(pic_bmp, sizeof(pic_bmp));
You should get 4 or 8 as this is the size of the pointer variable which
points to the actual data, not the size of the actual data. C arrays are
just a pointer (address) into memory without any knowledge of the array
boundaries. You need to put the size of the file somewhere into your code.
static char my_pic[] = {/* mydata */}
static int my_pic_size = 42;

Did you check rw != 0?

This is just a guess as i cannot test this now.

Christoph Nelles

E-Mail : @Christoph_Nelles
Jabber : eazrael at evilazrael.net ICQ : 78819723

PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt

static const unsigned short pic_bmp[] = {0x8e00b4, 0x4c008a, 0xa756c5, 0xe6adee,
0x963eb9, 0x580090, 0x000000, 0x570090, 0x9740ba, 0xe7b5ee, 0xd89ae5, 0x51008e, 0x000000,
0x000000, 0x000000, 0x000000, 0x7e2daa, 0xd999e5, 0xfed0ff, 0xe7bdf8, 0x9541bb,

0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000057, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000};

[…]
Any ideas on this?

It may or may not be relevant, but without knowing your compiler, I’d
assume that short is a 16-bit type (simply because that’s the only
candidate between the 8-bit char and the at least 16-bit int) while you
fill the array with 32-bit datum. I know that gcc would issue a warning,
maybe yours doesn’t?

As I mentioned, it may not be the root of your problem, but it’s certainly
a mismatch between your declared and actual data size.

Zoltan

i’ve somewhat given up on compiling SDL 1.3 myself with SDL_mixer support

is there a working download somewhere of the compiled frameworks for SDL 1.3 with mixer, image and ttf support ?

pleaaaaase ?

i found the http://www.libsdl.org/tmp/SDL-1.3.zip , but I can not find a working framework for mixer, image & ttf that links to 1.3

I have here some GIMP C-source dump made from .png picture. It is a structure and has some pixel
data size member (pixel_data[15 * 15 * 4 + 1]).

/* GIMP RGBA C-Source image dump (pic_gimp.c) */

static const struct {
unsigned int width;
unsigned int height;
unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */
unsigned char pixel_data[15 * 15 * 4 + 1];
} gimp_image = {
15, 15, 4,
"\216\0\264\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0.\0u\24\244\251\343\255\354"
"\345\311\207\333\337x$\246L\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0L\0\212"

"\0\0\0\0\0\32\10\0\0\0\0\0\0\0\0\0\0@\0\0\0\0\0\0\0\0\0\0\0\0\0",
};

it compiles with VC++ and is linking with the rest of the program.So to repeat:

  1. I have unsigned “extern struct *gimp_image;” defined in source file which is using it.

Now when we have data size,how can this be used in code? This code:

SDL_RWops *rw;

rw = SDL_RWFromConstMem(gimp_image.pixel_data, sizeof(gimp_image.pixel_data));

m_pic = SDL_LoadBMP_RW(rw, 0);

gives: error C2228: left of ‘.pixel_data’ must have class/struct/union type
error C2228: left of ‘.pixel_data’ must have class/struct/union type

at compile time.

dekyco

The error message is telling you you’re trying to treat the pointer to
your structure as a structure itself.

Try this instead, to make it an actual struct that you can use the dot
operator on:
extern struct gimp_image;

-JustinOn Thu, Feb 4, 2010 at 6:52 AM, dekyco wrote:

I have here some GIMP C-source dump made from .png picture. It is a
structure and has some pixel
data size member (pixel_data[15 * 15 * 4 + 1]).

/* GIMP RGBA C-Source image dump (pic_gimp.c) */

static const struct {
unsigned int width;
unsigned int height;
unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */
unsigned char pixel_data[15 * 15 * 4 + 1];
} gimp_image = {
15, 15, 4,
"\216\0\264\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0.\0u\24\244\251\343\255\354"
"\345\311\207\333\337x$\246L\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0L\0\212"

"\0\0\0\0\0\32\10\0\0\0\0\0\0\0\0\0\0@\0\0\0\0\0\0\0\0\0\0\0\0\0",
};

it compiles with VC++ and is linking with the rest of the program.So to
repeat:

  1. I have unsigned “extern struct *gimp_image;” defined in source file which
    is using it.

Now when we have data size,how can this be used in code? This code:

SDL_RWops *rw;

rw = SDL_RWFromConstMem(gimp_image.pixel_data,
sizeof(gimp_image.pixel_data));

m_pic = SDL_LoadBMP_RW(rw, 0);

gives: error C2228: left of ‘.pixel_data’ must have class/struct/union type
error C2228: left of ‘.pixel_data’ must have class/struct/union type

at compile time.

dekyco


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Just a dry run:

/* GIMP RGBA C-Source image dump (pic_gimp.c) */

static const struct {
unsigned int width;
unsigned int height;
unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */
unsigned char *pixel_data;
} gimp_image = {
15, 15, 4,

“\216\0\264\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0.\0u\24\244\251\343\255\354”

“\345\311\207\333\337x$\246L\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0L\0\212”

"\0\0\0\0\0\32\10\0\0\0\0\0\0\0\0\0\0@\0\0\0\0\0\0\0\0\0\0\0\0\0",
};

  1. I have unsigned “extern struct *gimp_image;” defined in source file
    which is using it.

Which is a little bit wrong, as you say: “i have a pointer, which is
defined else” and create directly an struct of this type.

rw = SDL_RWFromConstMem(gimp_image.pixel_data,
sizeof(gimp_image.pixel_data));

So, what are you using now? The pointer *gimp_image, then you need to use
gimp_image->pixeldata, or a global variable, then gimp_image.pixel_data.
Quite inconsistent. And the name of sizeof() seems to mislead you. sizeof()
tells you the size of the variable, which is either a simple type like
char, int, and similar or a pointer. If you use char[20] it tells the
compiler to reserve 20bytes in the scope (function, global) , but you
really get a pointer to these 20bytes. Yes, the information of the
20bytes gets lost. So, sizeof(gimp_image.pixel_data) just tells you how big
the pointer is, which 32bit, 48bit, 64bit, somewhere in this dimension, not
even anywhere near “15 * 15 * 4 + 1”.

gives: error C2228: left of ‘.pixel_data’ must have class/struct/union
type
error C2228: left of ‘.pixel_data’ must have class/struct/union
type

Sure, in the using source file you declared a pointer. Looks like you
haven’t understood C/C++ memory handling yet.

You may contact me via ICQ/Jabber if you want to, perhaps we can work out
something.On Thu, 04 Feb 2010 03:52:48 -0800, “dekyco” wrote:


Christoph Nelles

E-Mail : @Christoph_Nelles
Jabber : eazrael at evilazrael.net ICQ : 78819723

PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt