Archived

This topic is now archived and is closed to further replies.

BungoMan85

combining sprites into one big file?

Recommended Posts

sorry for the subject not being the most descriptive one ever, itd be one loooooong subject to accuratly describe what i need... anyways.... in my attempts at making a sprite based game i have come to realize something. having a ton a bmp files just sitting there along with the program isnt exactly an efficient or good idea at all. i was wondering then, how could i possibly go about taking all of the data for my bitmaps that are to be used as sprites and combine them into one huge file? yes i am WELL aware such a file for a game with a few thousand decent sized bitmaps could be upwards of 100-300 megs. i know this is very possible as i have played games that use something similar to that (and i have even modified the files so that different bitmaps are included in them...), namely ultima online. yeah OSI .mul files arent the best example of a good file format, in fact sometimes they''re just plain horrid, but that is essentialy what i need. i need to be able to load the resources for a bitmap from a file that isnt an actual bitmap, but rather is one giant collection of bitmaps. does anyone have a good idea as to how this can be achieved? Bungo!

Share this post


Link to post
Share on other sites
There are a couple of articles in the article section and on www.flipcode.com that describe virtual file systems. You can put any collection of files in those. The easiest way I can think of to create what you want is to store the number of bitmaps and their sizes into a header, along with an offset to the start of the bitmap. After that, you just store all the bitmaps rgb values in sequence. Something like this perhaps:

  
//file header

numbitmaps 2
//bitmap 1

width 64
height 64
offset 80
//bitmap 2

width 16
height 16
offset 4500
//all rgb values for bmp1

//all rgb values for bmp2




Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

Share this post


Link to post
Share on other sites
hmmm, that was actualy kind of what i was thinking. but im more concerned about how im going to get openGL to recognize the bitmaps stored in the file as a valid bitmap that can be drawn to a surface =/

Bungo!

Share this post


Link to post
Share on other sites
quote:
Original post by BungoMan85
hmmm, that was actualy kind of what i was thinking. but im more concerned about how im going to get openGL to recognize the bitmaps stored in the file as a valid bitmap that can be drawn to a surface =/



OpenGL doesn''t care about file formats. Heck you could pop up an input screen and start typing numbers in by hand! OGL would still draw it!

No matter what, you need to pass an array of data to OGL. This can be RGB, RGBA, BGR, whatever you like. No matter how you store it and how you retieve it. I guess you do not use do this so I assume you use GLaux to load BMP''s for you. I suggest you loose GLaux altogether (I''ve heard it has memory leaks) and write an image loader yourself. There are many good articles and tutorials about loading BMP''s, TGA''s, JPEG''s etcetera. I recommend TGA''s so you can add an alpha channel and make partially transparent textures. JPEG''s are very small but it has lossy compression (color bleeding).

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

Share this post


Link to post
Share on other sites
I second Kylotan, use Zip file where each sprite is in its own file (not a big image with many sprites).
Reasons:
1. You don't need to know how big the animation is. Each sprite is treated as an individual file/object independent of the others. Of course, to make the animation smooth, all must be of the same size.

2. The order of the animation can be sorted by the name of the sprites. For example: "walking001.bmp", "walking002.bmp" "walking003.bmp" and etc..And I found this much easier to manage since filename (or string) can be sorted inside the program and I don't have to bother with the size of each animation. "oh, since animation is 64x64, the second sprites is located at 64,0, the 3rd sprite is located at 128,0, etc..."

3. Safer. Users can't modify the sprites directly since they are inside a zip file. I know they can just open it with WinZip, but you have a better security instead of using plain bitmap files. You can use password to protect your zip files.

4. Smaller size. Bitmap size is insanely big. But in a zip, they are so tiny (depends on the picture, but ~90% compression is not a rare thing).

[edited by - alnite on May 8, 2003 1:55:09 PM]

[edited by - alnite on May 8, 2003 1:56:25 PM]

Share this post


Link to post
Share on other sites
I also agree on the motion, look up ZLIB, and foremost learn to load a file into memory then use it in memory for OpenGL...

Under Win32 the following APIs enable one to do so:
CreateFile - GetFileSize - CreateFileMapping - MapViewOfFile
(There is something sexy about accessing a file through an old-fashioned pointer. )

Of course if you use ZLIB, you need only alter it a tad to unzip into dynamic memory instead of opening a file to write in - saves disk access. Elegant and fast.

=^.^= Leaders and teachers should remember: It is best to offer others what they Need, not what they Want.

Share this post


Link to post
Share on other sites
quote:
Original post by Spacecat
=^.^= Leaders and teachers should remember: It is best to offer others what they Need , not what they Want .


There are distributions for win32 that feature file mapping by default.

Share this post


Link to post
Share on other sites