Indices

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Indices.php

The first one we carry over from the previous tutorials is the VertexDeclaration changes

So where we initialize myVertexDeclaration 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;

Now when we declare the array for our indices we will use either int[] or short[] depending on the graphics profile you have set in the properties for your project. If you aren’t sure which one you are using these profile setting can be found in solution explorer, in the properties of your game project (either right-click the project and select properties or double-click the grey properties folder under your project.)

Reach Profile =

Define your array like this:

short[] indices;

And in your SetUpIndices method, initialize it like this:

indices = new short[6];

HiDef Profile =

Define your array like this:

int[] indices;

And in your SetUpIndices method, initialize it like this:

indices = new int[6];

The next change is really simple as we did with DrawUserPrimitives in the world space tutorials the next two lines are condensed into one statement, from this:

device.VertexDeclaration = myVertexDeclaration;
device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, indices, 0, indices.Length / 3);

to this:

device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, indices, 0, indices.Length / 3, myVertexDeclaration);

Also to draw as a wireframe we will need to set the fill mode on the RasterizerState
by adding this line:
rs.FillMode = FillMode.WireFrame

 
instead of

device.RenderState.FillMode = FillMode.WireFrame;

underneath where we set:
rs.CullMode = CullMode.None;
in the earlier tutorials.

And that’s all of the changes needed to get this tutorial running under XNA Game Studio 4.0

Enjoy! Next up terrain basics.

Advertisements

2 thoughts on “Indices

  1. To see a wireframe instead of solid triangles you’ll also need to use
    rs.FillMode = FillMode.WireFrame;
    instead of
    device.RenderState.FillMode = FillMode.WireFrame;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s