# Is it possible to use an image, sound or font without importing them externally? [SDL2]

It's hard to explain my question, but I will try my best.

When loading sounds, images or fonts in SDL2 (with SDL_image, SDL_mixer, SDL_ttf) you need to load them from an external source path. For example, res/image.png - the issue I have with this is that the user can edit this file which changes the look of the game.

Is there a way in loading the asset internally? (If that's the right term?) So that it cannot be edited by other people.

Thanks.

What you are looking for is what is known as a "pack/package file" or "assets pack", these are just some of the common names. Most medium to large size games adopt this pattern of packing all loose game assets, such as textures and sounds, into a single file. This is done for three main reasons:

1) To save disk space by compressing the package file;

2) To make difficult for hackers to change game content;

3) To speed up loading and copying of files, since a single large file reduces seek time in the media and data fragmentation in the local File System.

A package file is usually a custom file format devised by the game developer, but most of them mimic a simple directory structure of an OS or implement a virtual File System. Some pack files are just ZIP files that you can open with any ZIP file explorer. Many games actually use plain ZIP files.

If security concerns are really high, you could also go to the extreme of encrypting the assets inside the package file. But this would not be very feasible for a game, since it would slow asset loading to a crawl.

Now regarding the SDL integration, if you had your game assets stored inside one ZIP file, for example, then you would open the ZIP and decompress the data in-memory, possibly using a library like miniZ, and then pass the raw decompressed bytes to one of the equivalent memory loading functions of SDL, like IMG_Load_RW().

You can hard code it in your code itself, for example if you import an image from a 2D array you can hard code it, you can do something similar to 3D models and even sound files (1D arrays) (at the lowest level they are all 1's and 0's and as such can be hard coded if they can be represented as 1's and 0's ), be warned through that this is a heavy load on your compiler and does not make for easy coding (by the way why don't you want your users to change things about your graphics?)

• Is there a lighter way of doing this? -- in response to your question, when I look at the folder containing some games like WoW, GMod etc there are no external image files, so I wanted to do something like that where they cannot be modified easily. – Ethan Webster Jul 11 '14 at 18:46