Trying to color a node created with an SMeshBuffer?

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
Spinland
Posts: 32
Joined: Fri May 14, 2010 1:06 pm
Location: Upstate NY, USA

Trying to color a node created with an SMeshBuffer?

Post by Spinland »

I'm trying to draw a basic box centered on the origin and then color it yellow, using an SMesh instead of reading the data in from a file. I have it mostly working, but for some reason I can't get the color to appear as anything but black. I have added a pair of lights between the node and the camera, and I've trued turning off EMF_LIGHTING, but still no luck. Here's the sample code I'm trying:

Code: Select all

	IMeshSceneNode* node=NULL;
	SMeshBuffer *buf = new SMeshBuffer();
	SMesh* BoxMesh = new SMesh();

	BoxMesh->addMeshBuffer(buf);
	buf->drop();
	
	buf->Vertices.set_used(8);
	buf->Indices.set_used(36);

	buf->Vertices[0].Pos.set(80,20,20);
	buf->Vertices[1].Pos.set(80,-20,-20);
	buf->Vertices[2].Pos.set(-80,-20,-20);
	buf->Vertices[3].Pos.set(-80,-20,20);
	buf->Vertices[4].Pos.set(-80,20,20);
	buf->Vertices[5].Pos.set(80,-20,20);
	buf->Vertices[6].Pos.set(-80,20,-20);	
	buf->Vertices[7].Pos.set(80,20,-20);
	
	buf->Vertices[0].Color = (255,255,255,0);
	buf->Vertices[1].Color = (255,255,255,0);
	buf->Vertices[2].Color = (255,255,255,0);
	buf->Vertices[3].Color = (255,255,255,0);
	buf->Vertices[4].Color = (255,255,255,0);
	buf->Vertices[5].Color = (255,255,255,0);
	buf->Vertices[6].Color = (255,255,255,0);
	buf->Vertices[7].Color = (255,255,255,0);

	buf->Indices[0] = 3;
	buf->Indices[1] = 5;
	buf->Indices[2] = 0;
	buf->Indices[3] = 0;
	buf->Indices[4] = 4;
	buf->Indices[5] = 3;
	
	buf->Indices[6] = 5;
	buf->Indices[7] = 1;
	buf->Indices[8] = 7;
	buf->Indices[9] = 7;
	buf->Indices[10] = 0;
	buf->Indices[11] = 5;
	
	buf->Indices[12] = 1;
	buf->Indices[13] = 2;
	buf->Indices[14] = 6;
	buf->Indices[15] = 6;
	buf->Indices[16] = 7;
	buf->Indices[17] = 1;
	
	buf->Indices[18] = 2;
	buf->Indices[19] = 3;
	buf->Indices[20] = 4;
	buf->Indices[21] = 4;
	buf->Indices[22] = 6;
	buf->Indices[23] = 2;
	
	buf->Indices[24] = 5;
	buf->Indices[25] = 3;
	buf->Indices[26] = 2;
	buf->Indices[27] = 2;
	buf->Indices[28] = 1;
	buf->Indices[29] = 5;

	buf->Indices[30] = 4;
	buf->Indices[31] = 0;
	buf->Indices[32] = 7;
	buf->Indices[33] = 7;
	buf->Indices[34] = 6;
	buf->Indices[35] = 4;
	
	buf->recalculateBoundingBox();
		
	BoxMesh->setMaterialFlag(EMF_LIGHTING, false);
	
	node = smgr->addMeshSceneNode(BoxMesh);
Could some kind soul point out where I'm going wrong (and if this is a correct way to use SMeshBuffer)?

Many thanks in advance!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

You can also create a box with createCubeMesh from the geometrycreator.

Check example 22 - it is there to test the behavior of different material & color combinations with and without light.
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
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

how about using colors instead of nothing saying numbers !?!?! :lol:

Code: Select all

   buf->Vertices[0].Color = SColor(255,255,255,0);
   buf->Vertices[1].Color = SColor(255,255,255,0);
   buf->Vertices[2].Color = SColor(255,255,255,0);
   buf->Vertices[3].Color = SColor(255,255,255,0);
   buf->Vertices[4].Color = SColor(255,255,255,0);
   buf->Vertices[5].Color = SColor(255,255,255,0);
   buf->Vertices[6].Color = SColor(255,255,255,0);
   buf->Vertices[7].Color = SColor(255,255,255,0);
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Spinland
Posts: 32
Joined: Fri May 14, 2010 1:06 pm
Location: Upstate NY, USA

Post by Spinland »

... but is the code (which is very rough--and simple--test code to try to make this work, it wasn't intended to be "pretty") itself incorrect? It's based on Tutorial 23.

Thanks again!
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

looks good so far... ;)
also I'm not sure, but I would change the last part to this:

Code: Select all

BoxMesh->recalculateBoundingBox();
   
node = smgr->addMeshSceneNode(BoxMesh);
BoxMesh->drop();

node->setMaterialFlag(EMF_LIGHTING, false);
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Spinland
Posts: 32
Joined: Fri May 14, 2010 1:06 pm
Location: Upstate NY, USA

Post by Spinland »

Many thanks to both of you. Thanks to your suggestions I have the test code working great now. Very much appreciated! 8)
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Don't forget that you can use the mesh manipulator to set colors of the indices instead of having to do it manually.
Spinland
Posts: 32
Joined: Fri May 14, 2010 1:06 pm
Location: Upstate NY, USA

Post by Spinland »

And even more thanks! As you deduced, I'd overlooked the manipulator functions. Fixed. :oops:
Post Reply