#include "SDL.h" #include #include int main(void) { SDL_Surface *screen; SDL_Surface *one; SDL_Rect rect; /* This is the RWops structure we'll be using */ SDL_RWops *rw; /* gzFile is the Zlib equivalent of FILE from stdio */ gzFile file; /* We'll be needing space to store our graphic into. The penguin graphic is about 12k, so we'll fake it for now. You'd want to figure out how much space you need for other graphics in a real application, though. */ Uint8 buffer[13000]; /* We'll need to store the actual size of the file when it comes in */ int filesize; SDL_Init(SDL_INIT_VIDEO); atexit(SDL_Quit); screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF); /* Opens up the file with Zlib */ file = gzopen("penguin.gz", "r"); /* Decompresses the file into memory (the buffer we set aside), 13000 bytes max. gzread returns the number of (decompressed) bytes it actually read, and we need that information for later. */ filesize = gzread(file, buffer, 13000); /* Gives us an RWops from memory - SDL_RWFromMem needs to know where the data is, and how big it is (thus why we saved the filesize) */ rw = SDL_RWFromMem(buffer, filesize); /* The function that does the loading doesn't change at all */ one = SDL_LoadBMP_RW(rw, 0); /* And clean up */ SDL_FreeRW(rw); gzclose(file); /* Haphazard way of getting stuff to the screen */ rect.x = rect.y = 20; rect.w = one -> w; rect.y = one -> h; SDL_BlitSurface(one, NULL, screen, &rect); SDL_Flip(screen); SDL_Delay(3000); }