Added support for external masks; this allows using JPEG even on images that need transparency. Reduced palmacacia from 800 KB to 300 KB using this feature
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8064 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
9306c5c7e6
commit
7ce7daa5ac
@ -863,6 +863,43 @@ video::ITexture *IrrDriver::getTexture(const std::string &filename,
|
||||
return out;
|
||||
} // getTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ITexture* IrrDriver::applyMask(video::ITexture* texture, const std::string& mask_path)
|
||||
{
|
||||
video::IImage* img =
|
||||
m_scene_manager->getVideoDriver()->createImage(texture, core::position2d<s32>(0,0), texture->getSize());
|
||||
|
||||
video::IImage* mask =
|
||||
m_scene_manager->getVideoDriver()->createImageFromFile(mask_path.c_str());
|
||||
|
||||
if (img == NULL || mask == NULL) return NULL;
|
||||
|
||||
if (img->lock() && mask->lock())
|
||||
{
|
||||
core::dimension2d<u32> dim = img->getDimension();
|
||||
for (unsigned int x = 0; x < dim.Width; x++)
|
||||
{
|
||||
for (unsigned int y = 0; y < dim.Height; y++)
|
||||
{
|
||||
video::SColor col = img->getPixel(x, y);
|
||||
video::SColor alpha = mask->getPixel(x, y);
|
||||
col.setAlpha( alpha.getRed() );
|
||||
img->setPixel(x, y, col, false);
|
||||
} // for y
|
||||
} // for x
|
||||
|
||||
mask->unlock();
|
||||
img->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return m_scene_manager->getVideoDriver()->addTexture(texture->getName().getPath().c_str(), img, NULL);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets the ambient light.
|
||||
* \param light The colour of the light to set.
|
||||
|
@ -105,6 +105,8 @@ public:
|
||||
gui::IGUIEnvironment *getGUI() const { return m_gui_env; }
|
||||
//irr::gui::IGUIFont *getRaceFont() const { return m_race_font; }
|
||||
|
||||
video::ITexture* IrrDriver::applyMask(video::ITexture* texture, const std::string& mask_path);
|
||||
|
||||
void displayFPS();
|
||||
/** this is not really used to process events, it's only used to shut down irrLicht's
|
||||
* chatty logging until the event handler is ready to take the task
|
||||
|
@ -89,6 +89,8 @@ Material::Material(const XMLNode *node, int index)
|
||||
node->get("backface-culling", &m_backface_culling );
|
||||
node->get("disable-z-write", &m_disable_z_write );
|
||||
|
||||
node->get("mask", &m_mask);
|
||||
|
||||
if (node->get("normal-map", &m_normal_map_tex))
|
||||
{
|
||||
m_normal_map = true;
|
||||
@ -158,7 +160,6 @@ Material::Material(const XMLNode *node, int index)
|
||||
|
||||
if (child_node->getName() == "sfx")
|
||||
{
|
||||
|
||||
initCustomSFX(child_node);
|
||||
}
|
||||
else if (child_node->getName() == "particles")
|
||||
@ -393,6 +394,12 @@ void Material::setMaterialProperties(video::SMaterial *m) const
|
||||
{
|
||||
int modes = 0;
|
||||
|
||||
if (m_mask.size() > 0)
|
||||
{
|
||||
video::ITexture* newtex = irr_driver->applyMask(m->getTexture(0), m_mask);
|
||||
if (newtex) m->setTexture(0, newtex);
|
||||
}
|
||||
|
||||
if (m_alpha_testing)
|
||||
{
|
||||
// Note: if EMT_TRANSPARENT_ALPHA_CHANNEL is used, you have to use
|
||||
|
@ -142,6 +142,8 @@ private:
|
||||
* is <0 the kart specific value will be used. */
|
||||
float m_zipper_fade_out_time;
|
||||
|
||||
std::string m_mask;
|
||||
|
||||
void init (unsigned int index);
|
||||
void install (bool is_full_path=false);
|
||||
void initCustomSFX(const XMLNode *sfx);
|
||||
|
Loading…
Reference in New Issue
Block a user