-
-
Notifications
You must be signed in to change notification settings - Fork 11
Embed Texture
Sometimes your segue effects need extra sample textures. We can embed textures in the header file. Or maybe you want to change one of the segues textures that comes with.
This is purely optional and if you want to make sharing your segues as easy as possible, is great practice.
One, download GIMP.
Two, open your source texture with GIMP.
Three, scale your texture down percent-wise as small as possible. If downsizing degrades the quality of the effect too much, you can skip this step.
Four, in GIMP, click FILE > EXPORT AS > Choose .c source code
Five, and the most important, CHECK RGBA/RGB. This will save our image in 32bit RGB that SFML uses.
Six, UNCHECK Glib types (guint8).
Seven, save. Open the file contents. You'll see a struct you can copy and paste into your segue like this:
/* exported from GIMP */
static const struct {
unsigned int width;
unsigned int height;
unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
unsigned char pixel_data[8 * 6 * 4 + 1];
} checkerboard_raw_32bit_rgba = {
8, 6, 4,
"LKL\377\\\\]\377\276\276\276\377qqq\377dcd\377UWU\377\010\010\010\377---\377"
"*)*\377\202\202\202\377uuu\377\016\016\016\377YXY\377\322\322\322\377>=>\377"
"\060\060\060\377\206\206\207\377\037\037\037\377kjk\377\346\346\346\377hgh\377"
"BAB\377ffg\377ZZZ\377EFE\377nnn\377VVW\377SSS\377|||\377\067\067\067\377\220"
"\220\220\377\034\034\033\377\377\377\377\377ddd\377a`a\377IHI\377:;;\377\000\000"
"\000\377xxy\377\021\022\021\377OPO\377&&&\377\247\247\247\377?>?\377\061\061\061"
"\377###\377\025\025\025\377HHH\377",
};
// Create a raw image buffer with our data exported from GIMP
sf::Image buffer;
buffer.create(checkerboard_raw_32bit_rgba.width, checkerboard_raw_32bit_rgba.height, checkerboard_raw_32bit_rgba.pixel_data);
// Load an sf::Texture with the image data
pattern.loadFromImage(buffer);
// Set the texture as one of our shader's uniform
shader.loadFromMemory(CHECKERBOARD_FRAG_SHADER, sf::Shader::Fragment);
shader.setUniform("texture", sf::Shader::CurrentTexture);
shader.setUniform("pattern", pattern);
To see a working example, view the Checkerboard segue.