Doubt

Hi,

I’am learning game develepment with sdl and I have a doubt.

Is there any way to pack all the bitmaps used in game as

single file .

Thanks,

Sachin.

you can use zlib to manualy compress/decompress the files yourself, or you can get SDL_Image and use compressed file formats like png or jpg.

zlib: http://www.gzip.org/zlib/

SDL_IMAGE: http://www.libsdl.org/projects/SDL_image/

have no doubts, SDL is very cool

-Atrix> ----- Original Message -----

From: sachina
To: sdl at libsdl.org
Sent: Wednesday, June 25, 2003 6:22 AM
Subject: [SDL] doubt

Hi,

I’am learning game develepment with sdl and I have a doubt.

Is there any way to pack all the bitmaps used in game as

single file .

Thanks,

Sachin.

Yes, it’s possible, but not with SDL.

Try searching on web for PAK file format
from ID Software. It’s a good sample.

sachina wrote:> Hi,

I’am learning game develepment with sdl and I have a doubt.

Is there any way to pack all the bitmaps used in game as

single file .

Thanks,

Sachin.

One way is to make a big giant image in a single file, and then
use SDL_BlitSurface with various source locations (SDL_Rect’s) to
get at it.

The most I’ve done like this is with bitmapped fonts.
I’ll create a 320 x 32 image containing the digits 0 through 9,
each 32x32.

Then, when I want to put score, level or #-of-lives on the screen,
I’ll make a function that blits the appropriate bits from my
"numbers" surface onto the screen.

The source SDL_Rect would look something like this:

src.x = numb * 32;
src.y = 0;
src.w = 32;
src.h = 32;

Where “numb” is a number between 0 and 9. If it’s a multi-digit number
(like a 6 digit score), I just do:

snprintf(tmp_string, sizeof(tmp_string), “%d”, score);

Which gives me a string I can traverse (“for (i=0; i<strlen(tmp_string); i++”)
and then “numb” would end up being:

numb = tmp_string[i] - ‘0’;

So that ASCII “0” (decimal 48) would end up as the integer ‘0’, which I
then use as an offset within my “numbers” surface.

Whew! Make sense?

Of course, what you MIGHT be looking for is a way to just throw a
collection of BMPs or PNGs into a “virtual directory”, which is just
a (probably compressed) archive of all the files, inside one file.
(Like a .tar, .zip, etc.)

For that, I think you want to look at PhysFS library. (I think)

I see others have responded. They’ve probably pointed you in that
direction, but I thought I’d still mention the possibility of using
a “matrix” or “array” style large image and getting at it with
source-rects and SDL_BlitSurface… since it works :slight_smile:

That and I’ve had WAY too much caffine for it being only 7:15am :wink:

-bill!On Wed, Jun 25, 2003 at 06:52:16PM +0530, sachina wrote:

Is there any way to pack all the bitmaps used in game as
single file .


bill at newbreedsoftware.com Got kids? Get Tux Paint!
http://newbreedsoftware.com/bill/ http://newbreedsoftware.com/tuxpaint/

you can use zlib to manualy compress/decompress the files yourself, or you can get SDL_Image and use compressed file formats like png or jpg.

What your suggestion seems to be only regarding compression.
(e.g., 100 images that instead of being 300K BMPs, end up being
15K JPGs… but it’s still 100 files)

I think what they wanted was to be able to throw ALL the files into ONE
file (like a ZIP… or in my example, just a regular image file, but with
all of the sprites stored within it).

Knowing about JPEG/PNG support from SDL_image and ZLIB support is
definitely useful, though! It’s just I don’t think that’s what the
question was. ;^)

Sachin asked:

Is there any way to pack all the bitmaps used in game as

-bill!On Wed, Jun 25, 2003 at 06:29:06AM -0700, Atrix Wolfe wrote:


bill at newbreedsoftware.com Got kids? Get Tux Paint!
http://newbreedsoftware.com/bill/ http://newbreedsoftware.com/tuxpaint/

If it’s just windows you’re worried about try www.molebox.com

It will compress, encrypt and pack your game into one exe. No code changes
needed.

ah yeah, i misread the question :stuck_out_tongue:

then i suggest PhysicsFS (havent used it myself but i heard good things from
this list)

http://www.icculus.org/physfs/> ----- Original Message -----

From: nbs@sonic.net (Bill Kendrick)
To:
Sent: Wednesday, June 25, 2003 7:22 AM
Subject: Re: [SDL] doubt

On Wed, Jun 25, 2003 at 06:29:06AM -0700, Atrix Wolfe wrote:

you can use zlib to manualy compress/decompress the files yourself, or
you can get SDL_Image and use compressed file formats like png or jpg.

What your suggestion seems to be only regarding compression.
(e.g., 100 images that instead of being 300K BMPs, end up being
15K JPGs… but it’s still 100 files)

I think what they wanted was to be able to throw ALL the files into ONE
file (like a ZIP… or in my example, just a regular image file, but with
all of the sprites stored within it).

Knowing about JPEG/PNG support from SDL_image and ZLIB support is
definitely useful, though! It’s just I don’t think that’s what the
question was. ;^)

Sachin asked:

Is there any way to pack all the bitmaps used in game as

-bill!


bill at newbreedsoftware.com Got kids? Get Tux
Paint!
http://newbreedsoftware.com/bill/
http://newbreedsoftware.com/tuxpaint/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Though you have a bunch of answers to this already, here’s what I did
before… Using SDL and the SDL_image library, you can load all the
images from an RWops thing. To put all the files into one huge file, in
linux and such you can do:
cat *.png > pictures.dat

(assuming all your pictures are PNG’s, though I think you can use any
image format except TGA since they don’t load with RWops). I’m sure
there’s something similar in Windows, though it’s been a while :).
Anyway, all that does is stick the images one after another in a single
file (here, pictures.dat). Note that this won’t really cut down on your
disk usage or anything, just the clutter. Then to load all the images
you would need to do something like this:

SDL_RWops *ops;
SDL_Surface *images[NUM_TEXTURES];
ops = SDL_RWFromFile(“pictures.dat”, “rb”);
if(!ops)
{
// error opening file
}

for(x=0;x<NUM_TEXTURES;x++) // see below for NUM_TEXTURES :slight_smile:
{
images[x] = IMG_Load_RW(ops, 0);

// load the image from the RWops - 0 means it isn't
// freed automatically
// once one image is loaded, the RWops automatically
// points to the next one in the list
// so we just loop until they're all loaded!

if(!images[x])
{
	// error occured loading the image
	// (perhaps a bad image was put into your file)
}

}
SDL_FreeRW(ops); // clean up the RWops

That’s basically it, though there are a few (big!) problems using this
method. First, is that (AFAIK) there is no way to go from your big file
back down into the individual files, without some extra indexing (such
as what tar would do). Though if you index the files, loading with
RWops would take some extra work. (So keep all your individual images
in a separate place!) Second, you have to be sure to keep your files
organized. You would need to know how many images you put in the file
so you can define NUM_TEXTURES somewhere, and also know in what order
they’re stored so you can actually use them properly in a program! You
can write some scripts to help you manage this part, though it may be
more difficult than if you just left all the images in their separate
files, and don’t worry about the “one huge file” thing.

Well, that’s the down and dirty SDL way of doing it. As others pointed
out, you’re probably better off using another library or something to
handle the stuff for you.

-MikeOn Wed, 2003-06-25 at 09:22, sachina wrote:

Hi,

I’am learning game develepment with sdl and I have a doubt.

Is there any way to pack all the bitmaps used in game as

single file .

Thanks,

Sachin.

I am using zziplib for this.

Thomas> ----- Original Message -----

From: sachina@w-o-i.com (sachina)
To:
Sent: Wednesday, June 25, 2003 3:22 PM
Subject: [SDL] doubt

Hi,

I’am learning game develepment with sdl and I have a doubt.

Is there any way to pack all the bitmaps used in game as

single file .

Thanks,

Sachin.

“sachina” ha scritto nel messaggio
news:002701c33b1c$cc2f97a0$9964a8c0 at seepz.woi.com
Hi,
I’am learning game develepment with sdl and I have a doubt.
Is there any way to pack all the bitmaps used in game as
single file .

Maybe this can help you…
http://www.kekkai.org/roger/sdl/rwops/rwops.html

It seems the last part (RWops + zziplib) it’s the best…–
Bye!