diff options
author | Thomas--S <Thomas--S@users.noreply.github.com> | 2016-07-02 17:58:08 +0200 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2016-08-12 15:20:30 +0200 |
commit | f21dae63390aa872062bcfc96fc6817b0fcfe601 (patch) | |
tree | 0a4ed31ac86eed3ca9ca85924473d0a67f8a6db1 /src | |
parent | c4e77b406aa73dd6db79f1183a0a65a32f284111 (diff) | |
download | minetest-f21dae63390aa872062bcfc96fc6817b0fcfe601.tar.gz minetest-f21dae63390aa872062bcfc96fc6817b0fcfe601.tar.bz2 minetest-f21dae63390aa872062bcfc96fc6817b0fcfe601.zip |
Add an [opacity:<r> texture modifier. Makes the base image transparent according to the given ratio. r must be between 0 and 255. 0 means totally transparent. 255 means totally opaque. Useful for texture overlaying.
Diffstat (limited to 'src')
-rw-r--r-- | src/client/tile.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/client/tile.cpp b/src/client/tile.cpp index ec8c95f02..3b5d2a3ae 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -1735,6 +1735,36 @@ bool TextureSource::generateImagePart(std::string part_of_name, baseimg->drop(); baseimg = image; } + /* + [opacity:R + Makes the base image transparent according to the given ratio. + R must be between 0 and 255. + 0 means totally transparent. + 255 means totally opaque. + */ + else if (str_starts_with(part_of_name, "[opacity:")) { + if (baseimg == NULL) { + errorstream << "generateImagePart(): baseimg == NULL " + << "for part_of_name=\"" << part_of_name + << "\", cancelling." << std::endl; + return false; + } + + Strfnd sf(part_of_name); + sf.next(":"); + + u32 ratio = mystoi(sf.next(""), 0, 255); + + core::dimension2d<u32> dim = baseimg->getDimension(); + + for (u32 y = 0; y < dim.Height; y++) + for (u32 x = 0; x < dim.Width; x++) + { + video::SColor c = baseimg->getPixel(x,y); + c.setAlpha(floor((c.getAlpha() * ratio) / 255 + 0.5)); + baseimg->setPixel(x,y,c); + } + } else { errorstream << "generateImagePart(): Invalid " |