First) of all never do drawing before scene->drawAll(), unless you really need it. Do all your manual drawing before EndScene().
Second) I'm going to show 2 ways how to see vertex colors in action. Remember, vertex has color, but has no material (which defines how to use it), vertex has position, but has no transformation matrix, which inform VideoDriver where to move to draw your vertices, because they are part of the mesh, and only then - mesh part of the scene. So:
next code will draw the cube with different vertex colors (this code supposed to be entered before your device->Run loop):
- Code: Select all
// ----------------------------------------------------------
// USING SCENE NODE
// ----------------------------------------------------------
MeshSceneNode X = scene.AddCubeSceneNode(100);
X.Position = new Vector3Df(-400, 0, -400);
X.GetMaterial(0).Lighting = false;
Vertex3D[] V = (Vertex3D[])X.Mesh.GetMeshBuffer(0).Vertices;
for (int k = 0; k < V.Length; k++) V[k].Color = new Color(140 + k * 10, k * 20, k * 5);
X.Mesh.GetMeshBuffer(0).UpdateVertices(V, 0);
// ----------------------------------------------------------
This cube is only draws because of scene->drawAll() call. SceneNode is such high level thing, which takes care about transformation matrix for us and the material (actualy material is a part of the meshbuffer, which we are accessing in the code above).
next code will draw a single triangle with different vertex colors (this code consist of two parts: initalization (before device->Run loop) and actually drawing (before driver->EndScene)):
- Code: Select all
// ----------------------------------------------------------
// USING OWN VERTICES
// ----------------------------------------------------------
List<Vertex3D> VERTICES = new List<Vertex3D>();
VERTICES.Add(new Vertex3D(-500, 0, -400, 0, 0, 0, new Color(100, 200, 120))); // using 3 different
VERTICES.Add(new Vertex3D(-700, 0, -400, 0, 0, 0, new Color(60, 240, 120))); // colors, because
VERTICES.Add(new Vertex3D(-600, 200, -400, 0, 0, 0, new Color(160, 140, 220))); // we want
List<uint> INDICES = new List<uint>();
INDICES.AddRange(new uint[] { 0, 2, 1 });
// ----------------------------------------------------------
and drawing:
- Code: Select all
driver.SetTransform(TransformationState.World, Matrix.Identity);
Material m = new Material();
m.Lighting = false;
driver.SetMaterial(m);
driver.DrawVertexPrimitiveList(VERTICES, INDICES);
take careful look at the code just before DrawVertexPrimitiveList call. What it does? Right! We just sew a legs to our vertices, so they can run just like SceneNode do. We said to video driver that it must use material without lighting, and he must move "drawing pensil" to the origin. If you do not do SetTransform() - you will have some transformation from what scene->DrawAll() has left (you cannot predict). The same with the material.
Add FPS camera fly around and check.
This code produces:
