How to set a color of a node?
How to set a color of a node?
I tried to "node->getMaterial(0).DiffuseColor = video::SColor(255, n, m p)" but it didn't work.
Re: How to set a color of a node?
Yeah, there is no unlighted material for pure diffuse material color (not sure why, probably because that's how fixed function pipeline worked back in the days). In short - material colors are only useful with Lighting or when you write your own shaders.
Your options:
1. Use vertex colors instead of material colors. Those tend to work with or without lighting. With lighting what exactly they do may depend a bit on ColorMaterial (I haven't experimented with that yet much myself). When you can use that it's the fastest solution (especially with lighting disabled). Unless you work with large models and have to changes this a lot, then it becomes a bit expensive as changing vertices starts to have some cost.
2. Enable lighting (SMaterial::Lighting enabled) and use the SMaterial::Emissive color. Set all other material colors to 0 and set the vertex colors also to 0. Emissive stands for self-lighting so that's the one you want. Downside - I think you can't do transparency that way. Also lights may still be calculated even thought you don't really use them that way.
3. Basically same as last one, just in another way: Enable lighting. Then either use diffuse cor ambient color. Then set the corresponding diffuse or ambient color factor in a light which reaches the mesh to 255 (for full brightness). Or alternatively set the global ambient to it (but then all meshes everywhere are affected). Basically - as soon as light is enabled the material color for those 2 is multiplied by the light color reaching that model. Their difference to my knowledge is just to help the coder to split those 2 (in general you give dynamic lights a diffuse color and the global ambient an ambient color). Probably a bad idea... don't think it has any upside to solution 2.
4. Use single colored textures. They are pretty easy and usually quick enough to create and never having untextured polygons can even make coding easier some day (once you get into shaders having to switch between colors and textures can become more annoying). Just be aware of not adding memory leaks as textures stay in cache (using the colors as names and doing a findTexture first works, but with too many the texture-lookup becomes expensive. So good solution if you don't have every color, but a limited selection).
5. Write your own shader. It's a good first shader to write as it's basically the simplest one you can do. Probably example shader only needs a tiny modfication.
For experimenting what exactly happens with the build-in material in Irrlicht give the MaterialViewer example a shot (then one in svn trunk works a bit better as usual).
Your options:
1. Use vertex colors instead of material colors. Those tend to work with or without lighting. With lighting what exactly they do may depend a bit on ColorMaterial (I haven't experimented with that yet much myself). When you can use that it's the fastest solution (especially with lighting disabled). Unless you work with large models and have to changes this a lot, then it becomes a bit expensive as changing vertices starts to have some cost.
2. Enable lighting (SMaterial::Lighting enabled) and use the SMaterial::Emissive color. Set all other material colors to 0 and set the vertex colors also to 0. Emissive stands for self-lighting so that's the one you want. Downside - I think you can't do transparency that way. Also lights may still be calculated even thought you don't really use them that way.
3. Basically same as last one, just in another way: Enable lighting. Then either use diffuse cor ambient color. Then set the corresponding diffuse or ambient color factor in a light which reaches the mesh to 255 (for full brightness). Or alternatively set the global ambient to it (but then all meshes everywhere are affected). Basically - as soon as light is enabled the material color for those 2 is multiplied by the light color reaching that model. Their difference to my knowledge is just to help the coder to split those 2 (in general you give dynamic lights a diffuse color and the global ambient an ambient color). Probably a bad idea... don't think it has any upside to solution 2.
4. Use single colored textures. They are pretty easy and usually quick enough to create and never having untextured polygons can even make coding easier some day (once you get into shaders having to switch between colors and textures can become more annoying). Just be aware of not adding memory leaks as textures stay in cache (using the colors as names and doing a findTexture first works, but with too many the texture-lookup becomes expensive. So good solution if you don't have every color, but a limited selection).
5. Write your own shader. It's a good first shader to write as it's basically the simplest one you can do. Probably example shader only needs a tiny modfication.
For experimenting what exactly happens with the build-in material in Irrlicht give the MaterialViewer example a shot (then one in svn trunk works a bit better as usual).
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm