Make my own image format in SDL

Started by
6 comments, last by theOcelot 14 years, 1 month ago
Hai guys, I want to make a game but without everyone can see my image in common file format. I'm using SDL to make my game, so how do I make my own file format and load the to SDL_Surface. Thanx
Advertisement
Hi Khan2007,

the image format is just something that is on your hard disk. So you can save your bitmap scrambled in a way that you like. However you have to remember how to read it. To draw it with the SDL you will have to unscramble it and convert it to an SDL_Surface.

An easier approach would be to encrypt the image data files on the disk and decrypt it when loading into the game. You could then still use standard formats and use the encryption only in your release builds which might help debugging. This is also the way networking in games is usually "secured".

Cheers,
fng

-- blog: www.fysx.org
An SDL_Surface holds the usual informations: color depth, resolution, pixels data and so on. As long as your own format contains this informations about the image you can store it the way you like. When you load it, just read those informations and build the surface.
Quote:Original post by Khan2007
I want to make a game but without everyone can see my image in common file format. I'm using SDL to make my game, so how do I make my own file format and load the to SDL_Surface.

Why bother? Just focus on making a fun game instead. After all, people can see your images in-game anyway...

You can never completely prevent people from looking at your images - you can only make it harder for them. As fng mentioned, you could use an (encrypted) archive file, but you're still likely just wasting your time.
Create-ivity - a game development blog Mouseover for more information.
Thanx for the advice guys, but my problem is SDL_Surface has so much complex structure that I can't figure it out. I've search for the net or SDL docs, but those don't help much. Maybe you all can explain to me the structure of SDL_Surface is.
For Captain P: I just want my games look professional, is that wrong?
Quote:Original post by Khan2007
For Captain P: I just want my games look professional, is that wrong?

You mean, you don't want the game to contain folders full of files? In that case, store your files in an archive file. You may want to take a look at physfs.
Create-ivity - a game development blog Mouseover for more information.
Quote:Thanx for the advice guys, but my problem is SDL_Surface has so much complex structure that I can't figure it out. I've search for the net or SDL docs, but those don't help much.
What format are your images in? And how are you converting them to SDL surfaces currently?

Whatever the answers to those two questions might be, you shouldn't have to change anything about how you load and convert the images for use with SDL. As noted previously, you can store the image files on disk in some sort of encrypted format. Then, when loading the files, you decrypt them immediately after loading them from disk; everything after that can stay the same.

Or is the problem that you're using some sort of 'load image from file' function that loads the image from disk directly? If so, you might want to look into SDL's 'rwops' feature, which allows you to load images and other resources directly from memory. This way, you can load the files from disk however you want (e.g. from an archive, as suggested by Captain P), and then create SDL surfaces from them as a separate step.
You can make assumptions about the format to simplify the file. If you assume that you'll only ever want one pixel format, all you need to do is add the dimensions at the beginning of the file and then dump in the pixel data. Then maybe encrypt it or something.

But yeah, save it for later, and work on making your game first. Just architect it so that you're not dependent on how images are loaded, so you can change it later to read from a custom file or archive or whatever.

This topic is closed to new replies.

Advertisement