|
|
|
@ -88,7 +88,7 @@ TexturePtr SpriteManager::loadSprite(int id)
|
|
|
|
|
return TexturePtr(new Texture(32, 32, 4, pixels));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TexturePtr SpriteManager::getSpriteTexture(int id)
|
|
|
|
|
TexturePtr SpriteManager::getSpriteTexture(int id, SpriteMask mask)
|
|
|
|
|
{
|
|
|
|
|
if(id == 0)
|
|
|
|
|
return g_graphics.getEmptyTexture();
|
|
|
|
@ -105,30 +105,28 @@ TexturePtr SpriteManager::getSpriteTexture(int id)
|
|
|
|
|
//TODO: release unused sprites textures after X seconds
|
|
|
|
|
// to avoid massive texture allocations
|
|
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
|
}
|
|
|
|
|
if(mask != SpriteMaskNone) {
|
|
|
|
|
auto pixels = texture->getPixels();
|
|
|
|
|
|
|
|
|
|
static RGBA maskColors[4] = { Color::red.rgba(), Color::green.rgba(), Color::blue.rgba(), Color::yellow.rgba() };
|
|
|
|
|
RGBA maskColor = maskColors[mask];
|
|
|
|
|
RGBA whiteColor = Color::white.rgba();
|
|
|
|
|
RGBA alphaColor = Color::alpha.rgba();
|
|
|
|
|
|
|
|
|
|
// convert pixels
|
|
|
|
|
// masked color -> white color
|
|
|
|
|
// any other color -> alpha color
|
|
|
|
|
for(int i=0;i<4096;i+=4) {
|
|
|
|
|
RGBA& currentColor = *(RGBA*)&pixels[i];
|
|
|
|
|
if(currentColor == maskColor)
|
|
|
|
|
currentColor = whiteColor;
|
|
|
|
|
else
|
|
|
|
|
currentColor = alphaColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TexturePtr SpriteManager::getSpriteMask(int id, SpriteMask mask)
|
|
|
|
|
{
|
|
|
|
|
TexturePtr tex = getSpriteTexture(id);
|
|
|
|
|
auto pixels = tex->getPixels();
|
|
|
|
|
|
|
|
|
|
static RGBA maskColors[4] = { Color::red.rgba(), Color::green.rgba(), Color::blue.rgba(), Color::yellow.rgba() };
|
|
|
|
|
RGBA maskColor = maskColors[mask];
|
|
|
|
|
RGBA whiteColor = Color::white.rgba();
|
|
|
|
|
RGBA alphaColor = Color::alpha.rgba();
|
|
|
|
|
|
|
|
|
|
// convert pixels
|
|
|
|
|
// masked color -> white color
|
|
|
|
|
// any other color -> alpha color
|
|
|
|
|
for(int i=0;i<4096;i+=4) {
|
|
|
|
|
RGBA& currentColor = *(RGBA*)&pixels[i];
|
|
|
|
|
if(currentColor == maskColor)
|
|
|
|
|
currentColor = whiteColor;
|
|
|
|
|
else
|
|
|
|
|
currentColor = alphaColor;
|
|
|
|
|
//TODO: cache sprites mask into a texture
|
|
|
|
|
return TexturePtr(new Texture(32, 32, 4, &pixels[0]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO: cache sprites mask into a texture
|
|
|
|
|
return TexturePtr(new Texture(32, 32, 4, &pixels[0]));
|
|
|
|
|
return texture;
|
|
|
|
|
}
|
|
|
|
|