Image data in source code

Hi Folks

Does anyone know of a way to include texture/image data in a program, so that you don’t have to load from a file? I’d like to be able to display an image on screen as soon as the SDL windows are created, without having to load my (large) texture file in first?

Thanks
Ed

Hello,

Gimp can save as source code, you can load that (uncompressed). There’s
also applications that let you convert say a raw png to “C code” like
bin2hex. You can then use SDL_RWops to load it from memory.

EdgarOn 04/01/11 11:37, ebyard wrote:

Hi Folks

Does anyone know of a way to include texture/image data in a program, so
that you don’t have to load from a file? I’d like to be able to display
an image on screen as soon as the SDL windows are created, without
having to load my (large) texture file in first?

Thanks
Ed


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

Hi,

normally this is done using resource files. You can emulate them platform
independent by converting the data file to “C code”. For example somthing
like
struct resource
{
int size;
char *data;
};

Then you need a small tool that opens the source file and outputs
something like
struct resource x = { 32, “PNG\x1b\x0a…\x01”}; where \xYY is the
hexadecimal representation of non-printable characters.

But you don’t want to include really large files into your executable.

Hi Folks

Does anyone know of a way to include texture/image data in a program,
so
that you don’t have to load from a file? I’d like to be able to display
an image on screen as soon as the SDL windows are created, without
havingOn Tue, 04 Jan 2011 02:37:26 -0800, “ebyard” <e_byard at yahoo.co.uk> wrote:
to load my (large) texture file in first?

Thanks
Ed


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

ebyard wrote:

Hi Folks

Does anyone know of a way to include texture/image data in a program, so
that you don’t have to load from a file? I’d like to be able to display
an image on screen as soon as the SDL windows are created, without
having to load my (large) texture file in first?

Thanks
Ed_______________________________________________
SDL mailing list
SDL@lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

This is expressly what the image format “xpm” is for.

Basically you can edit your image however you like, save it in XPM format,
and in your sourcefile, you can #include it like any other file and use
it.

Example,

#include “Play.xpm”

If you look in Play.xpm (The saved result varies by editor, and can be
modified easily):

/* XPM */
static char *play_xpm[] = {
“15 15 256 3”,
“000 c black”,
“001 c #040404”,
“002 c Gray3”,
“003 c #0C0C0C”,
“004 c #101010”,
“005 c Gray8”,
“006 c #181818”,
“007 c #202020”,
“008 c Gray14”,
“009 c #282828”,
“010 c Gray19”,
“011 c #484848”,
“012 c #505050”,
“013 c #585858”,
“014 c #606060”,
“015 c #646464”,
“016 c Gray47”,
“017 c #909090”,
“018 c #989898”,
“019 c Gray61”,
“020 c #A0A0A0”,
“021 c #A4A4A4”,
“022 c #C0C0C0”,
“023 c Gray80”,
“024 c #E4E4E4”,
“025 c Gray94”,
“026 c #F8F8F8”,
“027 c None”,
“027027027027027027027027027027027027027027027”,
“027019023027027027027027027027027027027027027”,
“027017001014024027027027027027027027027027027”,
“027024000000002016025027027027027027027027027”,
“027027011001000000004017026027027027027027027”,
“027027019012002000000000008021027027027027027”,
“027027024015013010005003001000010022027027027”,
“027027027018011009007004001000000006020027027”,
“027027024015013010005003000000010022027027027”,
“027027019012002000000000008021027027027027027”,
“027027011001000000004017026027027027027027027”,
“027024000000002016025027027027027027027027027”,
“027017001014024027027027027027027027027027027”,
“027019023027027027027027027027027027027027027”,
“027027027027027027027027027027027027027027027”
};

A useful link:
http://www.libsdl.org/projects/SDL_image/docs/SDL_image_28.html#SEC28