ResPack is a simple file-to-cpp-code converter . There are loads of them out there, nothing special about this one except it's using C++ which isn't really the cool thing among kids these days. But if you care this one will encapsulate the (mostly) binary blobs within a strict namespace.
If you want to embed external files in your executable, this will do the job.
The project has a bog standard Makefile with no dependecies.. Install G++ and execute:
$ make
For a full overview you can run the application with the help function:
$ ./respack -h
But basically ResPack just ask for wich resource files to involve, and optionally specify the unit name (as in unitname.h/unitname.cpp) and class name (as in classname_t) of the output.
A very basic example would be:
$ ./respack -u filename -c classname *.png
Would generate a filename.h/filename.cpp unit exposing classname() with all png files in the current working directory available. Assuming the CWD had 1.png and 2.png you would end up with something like:
filename.h:
#ifndef _FILENAME_H_
#define _FILENAME_H_
#include <stdint.h>
#include <string>
#include <vector>
class classname{
public:
// Structure for enumerating resources
struct resource{
resource(const std::string &Name,const size_t &Size);
std::string name;
size_t size;
};
// Structure for encapsulating resources
struct blob{
const uint8_t *data=0;
size_t size=0;
};
// Resources
static blob 1_png();
static blob 2_png();
// Resource enumerator
static std::vector<resource> Enumerate();
};
#endif
You can optionally use Enumerate() to enumerate the available sources, or 1_png()/2_png() to load known assets directly. The blob structure simply defines the embedded data with a size.
filename.cpp:
#include "filename.h"
classname::resource::resource(const std::string &Name,const size_t &Size){
name=Name;
size=Size;
}
std::vector<classname::resource> classname::Enumerate(){
std::vector<classname::resource> resources;
resources.push_back(resource("1_png",624));
resources.push_back(resource("2_png",624));
return resources;
}
classname::blob classname::1_png(){
const static uint8_t 1_png_buffer[]={
0x23,0x69,0x66,0x6e,0x64,0x65,0x66,0x20,0x5f,0x55,0x54,0x45,0x53,0x54,0x5f,0x52,0x45,0x53,0x5f,0x48,
0x5f,0x0a,0x23,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x5f,0x55,0x54,0x45,0x53,0x54,0x5f,0x52,0x45,0x53,
0x5f,0x48,0x5f,0x0a,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x64,0x69,0x6e,
0x74,0x2e,0x68,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x72,0x69,0x6e,
0x67,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x76,0x65,0x63,0x74,0x6f,0x72,0x3e,
0x0a,0x0a,0x63,0x6c,0x61,0x73,0x73,0x20,0x55,0x54,0x65,0x73,0x74,0x52,0x65,0x73,0x7b,0x0a,0x20,0x20,
0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x3b,0x0a,0x0a,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x2f,0x2f,0x20,0x53,0x74,0x72,0x75,0x63,0x74,0x75,0x72,0x65,0x20,0x66,0x6f,0x72,0x20,
0x69,0x7a,0x65,0x3d,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x3b,0x0a,0x0a,0x20,
0x2f,0x2f,0x20,0x52,0x65,0x73,0x6f,0x75,0x72,0x63,0x65,0x20,0x65,0x6e,0x75,0x6d,0x65,0x72,0x61,0x74,
0x6f,0x72,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x73,0x74,
0x64,0x3a,0x3a,0x76,0x65,0x63,0x74,0x6f,0x72,0x3c,0x72,0x65,0x73,0x6f,0x75,0x72,0x63,0x65,0x3e,0x20,
0x45,0x6e,0x75,0x6d,0x65,0x72,0x61,0x74,0x65,0x28,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x23,0x65,0x6e,
0x64,0x69,0x66,0x0a};
blob object;
object.data=1_png_buffer;
object.size=624;
return object;
}
classname::blob classname::2_png(){
const static uint8_t 2_png_buffer[]={
0x23,0x69,0x66,0x6e,0x64,0x65,0x66,0x20,0x5f,0x55,0x54,0x45,0x53,0x54,0x5f,0x52,0x45,0x53,0x5f,0x48,
0x5f,0x0a,0x23,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x5f,0x55,0x54,0x45,0x53,0x54,0x5f,0x52,0x45,0x53,
0x5f,0x48,0x5f,0x0a,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x64,0x69,0x6e,
0x74,0x2e,0x68,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x72,0x69,0x6e,
0x63,0x65,0x73,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x62,
0x6c,0x6f,0x62,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6e,
0x73,0x74,0x20,0x75,0x69,0x6e,0x74,0x38,0x5f,0x74,0x20,0x2a,0x64,0x61,0x74,0x61,0x3d,0x30,0x3b,0x0a,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x69,0x7a,0x65,0x5f,0x74,0x20,0x73,
0x69,0x7a,0x65,0x3d,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x3b,0x0a,0x0a,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2f,0x2f,0x20,0x52,0x65,0x73,0x6f,0x75,0x72,0x63,0x65,0x73,0x0a,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x62,0x6c,0x6f,0x62,0x20,
0x64,0x3a,0x3a,0x76,0x65,0x63,0x74,0x6f,0x72,0x3c,0x72,0x65,0x73,0x6f,0x75,0x72,0x63,0x65,0x3e,0x20,
0x45,0x6e,0x75,0x6d,0x65,0x72,0x61,0x74,0x65,0x28,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x23,0x65,0x6e,
0x64,0x69,0x66,0x0a};
blob object;
object.data=2_png_buffer;
object.size=624;
return object;
}
The assets are stored binary and can be extracted through the blob object.
No external libraries are needed. It only uses the standard C++ libraries.
Only the doxygen reference is available for now. You can generate this with:
make doxygen