Anyone Know How I can Integrate Images into a C++ Program?

closed account (N36fSL3A)
The question is pretty simple. I'd like to integrate an image into a C++ program.
closed account (Dy7SLyTq)
come on fred... sdl, sfml, opengl, allegro
closed account (N36fSL3A)
No, not loading images. I mean making them part of my executable.

I can display them just fine, and I know how to load them just fine.
Last edited on
closed account (Dy7SLyTq)
i think sdl makes it a part of it.
closed account (N36fSL3A)
It doesn't.

I want the image to be part of my program, no externals.
Make an array that contains your image data.
closed account (N36fSL3A)
I don't want to do it manually. Can I #include the image?
a general and cross platform method is,
1. modify your image or any of other binary format file in to base 64 encoded text file
2. use a byte array, and include the base 64 encoded text file, a normal #include should be able to work if nothing wrong in format, etc.
3. when app started, try to get the bytes from the base 64 encoded string
(1) Use something system-dependent:

Windows resources

The objcopy Linux command, see http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967)

(2) Use something to create a source file with an array of bytes containing your resource data, which you can compile and link into your application normally.

(3) Some compilers come with methods to help handle resources.


Also, check out Thor when you are ready to use your resources.
http://www.bromeon.ch/libraries/thor/

Hope this helps.
objcopy seems to be the most elegant of the options, as you just specify a variable in your program to access the file's contents. No file streams, no platform-specific resources, just a variable. The problem with this is that not all platforms have an objcopy-like utility, though it's not impossible to make one yourself (maybe cygwin provides it for windows?).
It isn't a variable -- it's a constant address to loaded program data. It's about the same thing as option (2) I gave above, just much more friendly to use. (And it avoids duplicating data into really big text files.)
Topic archived. No new replies allowed.