Jump to content
  • Advertisement
Sign in to follow this  
Mastadex

using zlib with SDL

This topic is 4736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to put all my files into several compressed archives so that no one can get at them also so that the files are neatly put into an archive so i dont get confused. Im going to try using zlib to compress everything into a single file and then when the game is loaded up, extract everything into memory. Im using SDL as the graphics backbone and PNG files to gold the images. im wondering is there a way to extract from a zip archive, a PNG file, into memory and then read the image similarly the same way as im reading directly form disk? here is my image loading function, it reads from file currently: // Image Loader SDL_Surface *LoadImage(const char *file, SDL_Surface *screen, bool AlphaFlag) { Uint32 color_key; SDL_Surface *tempImg; SDL_Surface *newImg; SDL_RWops *rwop; // Opens the file and reads it into a temp image rwop = SDL_RWFromFile(file, "rb"); tempImg = IMG_LoadPNG_RW(rwop); // If the Image is Alpha Enabled if (AlphaFlag) { // Creates a new Surface With Alpha Channel newImg = SDL_CreateRGBSurface(SDL_SWSURFACE, tempImg->w, tempImg->h, 32, rmask, gmask, bmask, amask); newImg = SDL_DisplayFormatAlpha(tempImg); }else{ // Creates a new Surface without an Alpha Channel newImg = SDL_CreateRGBSurface(SDL_SWSURFACE, tempImg->w, tempImg->h, 32, rmask, gmask, bmask, amask); newImg = SDL_DisplayFormat(tempImg); } if (tempImg) { // Kills the temp Image SDL_FreeSurface(tempImg); } // Sets the transparency if (AlphaFlag) { color_key = SDL_MapRGBA(screen->format, 0, 0, 0, 255); }else{ // Resort to Pure Green as Transparency color_key = SDL_MapRGB(screen->format, 0, 255, 0); } // Set Color Key SDL_SetColorKey(newImg, SDL_SRCCOLORKEY | SDL_RLEACCEL, color_key);// return newImg; }

Share this post


Link to post
Share on other sites
Advertisement
Best way is to find a library for .Zip files and look for functionality to do that.

/Shameless plug

I wrote a library based on Zlib that is a file archving/unarchiving toolset. It is made so that you could probabally accompish what you are after with its features. I am inthe process right now of getting my web page created with a new host and domain name, so I don't have the nice page where you can read about it, but you can download it and give it a try to see if it has what you need.

It is very well documented and comes with lots of examples, but if you have any questions, feel free to ask me about it. Since the weekend is almost here, I will finally have time to catch up on a few things, which will include programming again. So if there's anything that you think is missing, feel free to suggest! I will be working on that library some more.

Download

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can use unzip.c in the contrib directory that comes with zlib. It's quite easy to use to handle Zip files.

Share this post


Link to post
Share on other sites
The way I do it is to use the minizip add on library for zlib which is really easy to use. Then the basic process is this:

- read image data into memory
- use IMG_Load(SDL_RWFromMem(mem, buffsize)) to load the image data to an SDL_Surface*

Dead simple and can be done in about 20-30 lines of code (including extraction and loading), possibly less.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!