summaryrefslogtreecommitdiff
path: root/src/tile.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-10-15 02:28:57 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-10-15 02:28:57 +0300
commit43a28f04fa3ddf4b612f58c25a896293a01567e3 (patch)
tree58ca2cac232c28ffd59609ad3998b97628f13e33 /src/tile.cpp
parent080002f8ed1af6d34cdc6f5abff0f51586ca831c (diff)
downloadminetest-43a28f04fa3ddf4b612f58c25a896293a01567e3.tar.gz
minetest-43a28f04fa3ddf4b612f58c25a896293a01567e3.tar.bz2
minetest-43a28f04fa3ddf4b612f58c25a896293a01567e3.zip
mobv2
Diffstat (limited to 'src/tile.cpp')
-rw-r--r--src/tile.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/tile.cpp b/src/tile.cpp
index ac5965e9f..986d6bbf1 100644
--- a/src/tile.cpp
+++ b/src/tile.cpp
@@ -1055,6 +1055,120 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
}
}
/*
+ "[makealpha:R,G,B:filename.png"
+ Use an image with converting one color to transparent.
+ */
+ else if(part_of_name.substr(0,11) == "[makealpha:")
+ {
+ if(baseimg != NULL)
+ {
+ dstream<<"WARNING: generate_image(): baseimg!=NULL "
+ <<"for part_of_name=\""<<part_of_name
+ <<"\", cancelling."<<std::endl;
+ return false;
+ }
+
+ Strfnd sf(part_of_name.substr(11));
+ u32 r1 = stoi(sf.next(","));
+ u32 g1 = stoi(sf.next(","));
+ u32 b1 = stoi(sf.next(":"));
+ std::string filename = sf.next("");
+
+ std::string path = getTexturePath(filename.c_str());
+
+ dstream<<"INFO: generate_image(): Loading path \""<<path
+ <<"\""<<std::endl;
+
+ video::IImage *image = driver->createImageFromFile(path.c_str());
+
+ if(image == NULL)
+ {
+ dstream<<"WARNING: generate_image(): Loading path \""
+ <<path<<"\" failed"<<std::endl;
+ }
+ else
+ {
+ core::dimension2d<u32> dim = image->getDimension();
+ baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
+
+ for(u32 y=0; y<dim.Height; y++)
+ for(u32 x=0; x<dim.Width; x++)
+ {
+ video::SColor c = image->getPixel(x,y);
+ u32 r = c.getRed();
+ u32 g = c.getGreen();
+ u32 b = c.getBlue();
+ if(!(r == r1 && g == g1 && b == b1))
+ continue;
+ c.setAlpha(0);
+ image->setPixel(x,y,c);
+ }
+ // Blit
+ image->copyTo(baseimg);
+
+ image->drop();
+ }
+ }
+ /*
+ "[makealpha2:R,G,B;R2,G2,B2:filename.png"
+ Use an image with converting two colors to transparent.
+ */
+ else if(part_of_name.substr(0,12) == "[makealpha2:")
+ {
+ if(baseimg != NULL)
+ {
+ dstream<<"WARNING: generate_image(): baseimg!=NULL "
+ <<"for part_of_name=\""<<part_of_name
+ <<"\", cancelling."<<std::endl;
+ return false;
+ }
+
+ Strfnd sf(part_of_name.substr(12));
+ u32 r1 = stoi(sf.next(","));
+ u32 g1 = stoi(sf.next(","));
+ u32 b1 = stoi(sf.next(";"));
+ u32 r2 = stoi(sf.next(","));
+ u32 g2 = stoi(sf.next(","));
+ u32 b2 = stoi(sf.next(":"));
+ std::string filename = sf.next("");
+
+ std::string path = getTexturePath(filename.c_str());
+
+ dstream<<"INFO: generate_image(): Loading path \""<<path
+ <<"\""<<std::endl;
+
+ video::IImage *image = driver->createImageFromFile(path.c_str());
+
+ if(image == NULL)
+ {
+ dstream<<"WARNING: generate_image(): Loading path \""
+ <<path<<"\" failed"<<std::endl;
+ }
+ else
+ {
+ core::dimension2d<u32> dim = image->getDimension();
+ baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
+
+ for(u32 y=0; y<dim.Height; y++)
+ for(u32 x=0; x<dim.Width; x++)
+ {
+ video::SColor c = image->getPixel(x,y);
+ u32 r = c.getRed();
+ u32 g = c.getGreen();
+ u32 b = c.getBlue();
+ if(!(r == r1 && g == g1 && b == b1) &&
+ !(r == r2 && g == g2 && b == b2))
+ continue;
+ c.setAlpha(0);
+ image->setPixel(x,y,c);
+ }
+ // Blit
+ image->copyTo(baseimg);
+
+ image->drop();
+ }
+ }
+ /*
[inventorycube{topimage{leftimage{rightimage
In every subimage, replace ^ with &.
Create an "inventory cube".