[SOLVED] Problem Changing Vertex Colours

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
EvilDavo
Posts: 17
Joined: Sun Sep 27, 2009 12:20 pm
Location: Australia

[SOLVED] Problem Changing Vertex Colours

Post by EvilDavo »

I'm working on a custom lighting solution and want to display it.
Rather than go through the complexity of setting up textures and lightmaps,
I decided that for now, simply changing the vertex colours would be enough.

But I'm having no luck changing the vertex colours.

I've gone down to the meshBuffer nitty gritty and have changed the vertex colours, then setDirty( EBT_VERTEX );
It has no effect. Still no effect with lighting turned off.
It's frustrating changing things but seeing absolutely no effect.
How do I do this?

Thanks.
Last edited by EvilDavo on Fri Oct 22, 2010 6:32 pm, edited 1 time in total.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Post by REDDemon »

any code can help to help you.

you have also to set the correct lighting for the material of your mesh since there are some lighting systems that ignore vertex colors (and it is done by default?)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

Leave lighting enabled, set ambient/diffuse/specular/emissive colors of the material to 0, then material.ColorMaterial to ECM_EMISSIVE and it should work, i think.
EvilDavo
Posts: 17
Joined: Sun Sep 27, 2009 12:20 pm
Location: Australia

Post by EvilDavo »

I figured it out. Have to call setMesh afterwards for it to take effect.
Thanks for the advice. It doesn't work without using ECM_EMISSIVE, so that was very useful to know.

If anyone's interested this is how I changed the colours per vertex.

Code: Select all

	scene::IMesh* mesh = meshNode->getMesh();
	for (unsigned i=0; i<mesh->getMeshBufferCount(); ++i)
	{
		video::SMaterial &mat = mesh->getMeshBuffer(i)->getMaterial();
		mat.AmbientColor = video::SColor(0,0,0,0);
		mat.DiffuseColor = video::SColor(0,0,0,0);
		mat.SpecularColor = video::SColor(0,0,0,0);
		mat.EmissiveColor = video::SColor(0,0,0,0);
		mat.ColorMaterial = video::ECM_EMISSIVE;
		
		video::S3DVertex *vertex = (video::S3DVertex*)(mesh->getMeshBuffer(i)->getVertices());
		for (unsigned j=0; j<mesh->getMeshBuffer(i)->getVertexCount(); ++j)
		{
			vertex[j].Color = video::SColor(255,255,0,0); // set the colour per-vertex. Obviously, I'll have different colours for each vertex, but for simplicity, the colour red will do here
		}
	}
	meshNode->setMesh( mesh );
Post Reply