Skip to content
Permalink
Browse files

Add an [opacity:<r> texture modifier. Makes the base image transparen…

…t according to the given ratio. r must be between 0 and 255. 0 means totally transparent. 255 means totally opaque. Useful for texture overlaying.
  • Loading branch information
Thomas--S authored and nerzhul committed Aug 12, 2016
1 parent c4e77b4 commit f21dae63390aa872062bcfc96fc6817b0fcfe601
Showing with 40 additions and 0 deletions.
  1. +10 −0 doc/lua_api.txt
  2. +30 −0 src/client/tile.cpp
@@ -292,6 +292,16 @@ Example:

default_sandstone.png^[resize:16x16

#### `[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.

Example:

default_sandstone.png^[opacity:127

#### `[brighten`
Brightens the texture.

@@ -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 "

2 comments on commit f21dae6

@est31

This comment has been minimized.

Copy link
Contributor

@est31 est31 replied Aug 13, 2016

@nerzhul can you please make commit messages multiline when pushing them? single lines are very annoying. Otherwise thanks for the review + merge.

@nerzhul

This comment has been minimized.

Copy link
Member

@nerzhul nerzhul replied Aug 14, 2016

@est31 noted&

Please sign in to comment.
You can’t perform that action at this time.