Change alpha value of mesh in Irrlicht

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Donald Duck
Posts: 34
Joined: Sat Jan 21, 2017 6:51 pm
Location: Duckburg
Contact:

Change alpha value of mesh in Irrlicht

Post by Donald Duck »

I have a IMeshSceneNode that is usually not transparent, and I would like to make it semi-transparent under certain conditions. Something like this:

Code: Select all

if(condition){
    mesh->setAlpha(128);    //semi-transparent
}
else{
    mesh->setAlpha(255);    //not transparent
}
Is there any way I can do this in Irrlicht?
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: Change alpha value of mesh in Irrlicht

Post by MartinVee »

Searching the forums, I found that snippet of code that should do what you want :

Code: Select all

 
IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
IMeshManipulator *manipulator = smgr->getMeshManipulator();
 
int alpha = 128;
manipulator->setVertexColorAlpha(mesh->getMesh(0),alpha);
 
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Change alpha value of mesh in Irrlicht

Post by CuteAlien »

Basically as MartinVee wrote, but you also need a material which uses vertex colors (EMT_TRANSPARENT_VERTEX_ALPHA or a custom shader ... for others you have to experiment but most won't use it).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Change alpha value of mesh in Irrlicht

Post by Mel »

So far, materials have the difuse color which also might change the alpha value, you can try that.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply