In this tutorial there are only some small changes to the VertexDeclaration code, since now the built-in Vertex types implement an interface to get the declaration. This generally cuts a lot of lines of code from your project since you dont need to worry about the declarations unless you’re implementing custom types, which will be used in later tutorials.
So where we initialize myVertexDeclaration somewhere in your SetUpVertices method instead of creating a new instance like so:
myVertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements);
we can use the one from VertexPositionColor which looks like this:
myVertexDeclaration = VertexPositionColor.VertexDeclaration;
This declaration isn’t strictly necessary for this tutorial but it sets us up ready for a later tutorial when we will need to use it.
All we have to do now is tell the device to draw the triangle! Go to our Draw method, where we should draw the triangle after the call to pass.Apply:
We are going to slightly alter the code in this section from
device.VertexDeclaration = myVertexDeclaration;
device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);
device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1, myVertexDeclaration);
Notice now how this is only one line of code versus two now the VertexDeclaration is sent to the graphics card in the same statement that we tell it to draw the triangle. Again for this vertex type we don’t have to supply the VertexDeclaration as a parameter but for the purposes of a later tutorial we will specify it here.
Next step World space!