Code: Select all
virtual void makeColorKeyTexture(video::ITexture* texture, video::SColor minColor, video::SColor maxColor ) = 0;
Code: Select all
virtual void makeColorKeyTexture(video::ITexture* texture, video::SColor minColor, video::SColor maxColor );
Code: Select all
void CNullDriver::makeColorKeyTexture( video::ITexture* texture, video::SColor minColor, video::SColor maxColor )
{
if (!texture)
return;
if (texture->getColorFormat() != ECF_A1R5G5B5 &&
texture->getColorFormat() != ECF_A8R8G8B8 )
{
os::Printer::log("Error: Unsupported texture color format for making color key channel.", ELL_ERROR);
return;
}
if (texture->getColorFormat() == ECF_A1R5G5B5)
{
s16 *p = (s16*)texture->lock();
if (!p)
{
os::Printer::log("Could not lock texture for making color key channel.", ELL_ERROR);
return;
}
core::dimension2d<s32> dim = texture->getSize();
s32 pitch = texture->getPitch() / 2;
for (s32 x=0; x<pitch; ++x)
{
for (s32 y=0; y<dim.Height; ++y)
{
video::SColor texColor = A1R5G5B5toA8R8G8B8( p[y*pitch+x] );
if( texColor.getAlpha() <= maxColor.getAlpha() &&
texColor.getAlpha() >= minColor.getAlpha() &&
texColor.getBlue() <= maxColor.getBlue() &&
texColor.getBlue() >= minColor.getBlue() &&
texColor.getGreen() <= maxColor.getGreen() &&
texColor.getGreen() >= minColor.getGreen() &&
texColor.getRed() <= maxColor.getRed() &&
texColor.getRed() >= minColor.getRed() )
{
texColor.setAlpha( 0 );
p[y*pitch+x] = texColor.toA1R5G5B5();
}
}
}
texture->unlock();
}
else
{
s32 *p = (s32*)texture->lock();
if (!p)
{
os::Printer::log("Could not lock texture for making color key channel.", ELL_ERROR);
return;
}
core::dimension2d<s32> dim = texture->getSize();
s32 pitch = texture->getPitch() / 4;
for (s32 x=0; x<pitch; ++x)
{
for (s32 y=0; y<dim.Height; ++y)
{
video::SColor texColor = p[y*pitch+x];
if( texColor.getAlpha() <= maxColor.getAlpha() &&
texColor.getAlpha() >= minColor.getAlpha() &&
texColor.getBlue() <= maxColor.getBlue() &&
texColor.getBlue() >= minColor.getBlue() &&
texColor.getGreen() <= maxColor.getGreen() &&
texColor.getGreen() >= minColor.getGreen() &&
texColor.getRed() <= maxColor.getRed() &&
texColor.getRed() >= minColor.getRed() )
{
texColor.setAlpha( 0 );
p[y*pitch+x] = texColor.toA8R8G8B8();
}
}
}
texture->unlock();
}
}
Code: Select all
video::ITexture* landMask = VideoDriver->getTexture( "data/planets/earth/earthmask1k_2.jpg" );
VideoDriver->makeColorKeyTexture( landMask, video::SColor( 0, 0, 0, 0 ), video::SColor( 255, 127, 127, 127 ) );
landMask->regenerateMipMapLevels();