From e8a9578774d1777e45cfad0c17ae16122f919dd4 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 23 Nov 2011 00:27:12 +0200 Subject: [PATCH] Add texture modifier [brighten and modify [toalpha to modify existing texture, not read a new base --- src/nodedef.cpp | 4 +-- src/tile.cpp | 79 ++++++++++++++++++++++++++++--------------------- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 0e48c8c0..a3285197 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -529,8 +529,8 @@ public: f->drawtype = NDT_NORMAL; f->solidness = 1; for(u32 i=0; i<6; i++){ - f->tname_tiles[i] = std::string("[noalpha:") - + f->tname_tiles[i]; + f->tname_tiles[i] = f->tname_tiles[i] + + std::string("^[noalpha"); } } break; diff --git a/src/tile.cpp b/src/tile.cpp index 23058012..f18086f4 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -460,6 +460,8 @@ u32 TextureSource::getTextureId(const std::string &name) // Draw a progress bar on the image void make_progressbar(float value, video::IImage *image); +// Brighten image +void brighten(video::IImage *image); /* Generate image based on a string like "stone.png" or "[crack0". @@ -1306,53 +1308,46 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, make_progressbar(value, baseimg); } /* - "[noalpha:filename.png" - Use an image without it's alpha channel. + "[brighten" + */ + else if(part_of_name.substr(0,9) == "[brighten") + { + if(baseimg == NULL) + { + errorstream<<"generate_image(): baseimg==NULL " + <<"for part_of_name=\""< dim = baseimg->getDimension(); - video::IImage *image = sourcecache->getOrLoad(filename, device); - - if(image == NULL) + // Set alpha to full + for(u32 y=0; y dim = image->getDimension(); - baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); - - // Set alpha to full - for(u32 y=0; ygetPixel(x,y); - c.setAlpha(255); - image->setPixel(x,y,c); - } - // Blit - image->copyTo(baseimg); - - image->drop(); + video::SColor c = baseimg->getPixel(x,y); + c.setAlpha(255); + baseimg->setPixel(x,y,c); } } /* @@ -1650,3 +1645,21 @@ void make_progressbar(float value, video::IImage *image) } } +void brighten(video::IImage *image) +{ + if(image == NULL) + return; + + core::dimension2d dim = image->getDimension(); + + for(u32 y=0; ygetPixel(x,y); + c.setRed(0.5 * 255 + 0.5 * (float)c.getRed()); + c.setGreen(0.5 * 255 + 0.5 * (float)c.getGreen()); + c.setBlue(0.5 * 255 + 0.5 * (float)c.getBlue()); + image->setPixel(x,y,c); + } +} +