diff options
author | RealBadAngel <maciej.kasatkin@o2.pl> | 2015-06-22 04:34:56 +0200 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2015-06-27 03:42:01 +0200 |
commit | ffd16e3feca90c356c55898de2b9f3f5c6bc5c98 (patch) | |
tree | 8fb350ba1d2afaa39b9d333290e16a68168a4ddd /src/client | |
parent | 3376d2e114767eef06b87645edefcd2d42696919 (diff) | |
download | minetest-ffd16e3feca90c356c55898de2b9f3f5c6bc5c98.tar.gz minetest-ffd16e3feca90c356c55898de2b9f3f5c6bc5c98.tar.bz2 minetest-ffd16e3feca90c356c55898de2b9f3f5c6bc5c98.zip |
Add minimap feature
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/tile.cpp | 40 | ||||
-rw-r--r-- | src/client/tile.h | 2 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/client/tile.cpp b/src/client/tile.cpp index eba52033a..cf8061982 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -382,6 +382,8 @@ public: video::IImage* generateImage(const std::string &name); video::ITexture* getNormalTexture(const std::string &name); + video::SColor getTextureAverageColor(const std::string &name); + private: // The id of the thread that is allowed to use irrlicht directly @@ -2008,3 +2010,41 @@ video::ITexture* TextureSource::getNormalTexture(const std::string &name) } return NULL; } + +video::SColor TextureSource::getTextureAverageColor(const std::string &name) +{ + video::IVideoDriver *driver = m_device->getVideoDriver(); + video::SColor c(0, 0, 0, 0); + u32 id; + video::ITexture *texture = getTexture(name, &id); + video::IImage *image = driver->createImage(texture, + core::position2d<s32>(0, 0), + texture->getOriginalSize()); + u32 total = 0; + u32 tR = 0; + u32 tG = 0; + u32 tB = 0; + core::dimension2d<u32> dim = image->getDimension(); + u16 step = 1; + if (dim.Width > 16) + step = dim.Width / 16; + for (u16 x = 0; x < dim.Width; x += step) { + for (u16 y = 0; y < dim.Width; y += step) { + c = image->getPixel(x,y); + if (c.getAlpha() > 0) { + total++; + tR += c.getRed(); + tG += c.getGreen(); + tB += c.getBlue(); + } + } + } + image->drop(); + if (total > 0) { + c.setRed(tR / total); + c.setGreen(tG / total); + c.setBlue(tB / total); + } + c.setAlpha(255); + return c; +} diff --git a/src/client/tile.h b/src/client/tile.h index 38f8bb623..674da66f2 100644 --- a/src/client/tile.h +++ b/src/client/tile.h @@ -110,6 +110,7 @@ public: virtual video::ITexture* generateTextureFromMesh( const TextureFromMeshParams ¶ms)=0; virtual video::ITexture* getNormalTexture(const std::string &name)=0; + virtual video::SColor getTextureAverageColor(const std::string &name)=0; }; class IWritableTextureSource : public ITextureSource @@ -131,6 +132,7 @@ public: virtual void insertSourceImage(const std::string &name, video::IImage *img)=0; virtual void rebuildImagesAndTextures()=0; virtual video::ITexture* getNormalTexture(const std::string &name)=0; + virtual video::SColor getTextureAverageColor(const std::string &name)=0; }; IWritableTextureSource* createTextureSource(IrrlichtDevice *device); |