Seems I've answered my own question. Here are the changes you need to make to get the Primitive Tutorials to work in XNA 4.0.
When creating a BasicEffect change "basicEffect = new BasicEffect(GraphicsDevice, null);" to "basicEffect = new BasicEffect(GraphicsDevice);". The second parameter has been removed.
When drawing the primitives you'll change this code:
"basicEffect.Begin();
basicEffect.World = world;
basicEffect.View = view;
basicEffect.Projection = projection;
basicEffect.VertexColorEnabled = true;
GraphicsDevice.VertexDeclaration = new VertexDeclaration(GraphicsDevice,
VertexPositionColor.VertexElements);
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Begin();
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);
pass.End();
}
basicEffect.End();"
To look like this:
"basicEffect.World = world;
basicEffect.View = view;
basicEffect.Projection = projection;
basicEffect.VertexColorEnabled = true;
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);
}"
The Begin() and End() calls have been removed and each EffectPass must be Applied (Apply()) first. Also, you don't need the VertexDeclaration.
To draw using vertexBuffers and IndexBuffers the code changes from this:
"graphics.GraphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionColor.SizeInBytes);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);"
To something like this:
"graphics.GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);"
To make this more flexible and work with buffers outside of the tutorial change the DrawIndexedPrimitives call to look like this:
"graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.VertexCount, 0, indexBuffer.IndexCount / 3);"
I divided the indexBuffer count by 3 in this case because each triangle is made from 3 verticies. If you are using lines or points this would be different… but triangles are most common for 3D.
That should get the tutorials working with XNA 4.0.
On a side note…. when drawing triangles normally only 1 side is drawn, the other side is transparent. This is determined based on the order of the vertices. If the 3 verticies making 1 triangle are in clockwise order the default behavior is to draw it, if they are in counter-clockwise order the default behavior is to make them transparent. To change this behavior you must change the CullMode of the graphics device. This is different in XNA 4.0. Here's how to do it:
Add this to your Draw command or Initialization:
"RasterizerState state = new RasterizerState();
state.CullMode = CullMode.None;
graphics.GraphicsDevice.RasterizerState = state;"
That's it! Have fun, and let me know if you run into issues running your code in XNA 4.0.