Textures

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2/Textures.php

This tutorial should be quite simple if you have been following the earlier ones as we are covering familiar ground with changes only to the VertexDeclaration and the effects API.

When we declare the variables at the top of the class

Remove this line:

VertexDeclaration texturedVertexDeclaration;

and in the SetUpVertices() method we can get rid of the statement where we assign to that variable:

texturedVertexDeclaration = new VertexDeclaration(device, VertexPositionTexture.VertexElements);

Now for the changes to the effects API in our Draw() method the lines effect.Begin(); and effect.End(); are no longer necessary!

Whilst iterating over the effect passes the methods pass.Begin() and pass.End() have been simplified into one statement pass.Apply()

As we know it is also no longer necessary to explicitly tell the graphics card the VertexDeclaration as this is done implicitly when we specify the vertex type so the following line can be removed:

device.VertexDeclaration = texturedVertexDeclaration;

Which means the loop

foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{

pass.Begin();

device.VertexDeclaration = texturedVertexDeclaration;
device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);

pass.End();

}
effect.End();

becomes:

foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{

pass.Apply();

device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);

}

If you are following the tutorial step by step rather than jumping ahead (no cheating now…) then when we alter the SetUpVertices() method again we need to remove this one:

texturedVertexDeclaration = new VertexDeclaration(device, VertexPositionTexture.VertexElements);

And that’s it! Next step…Loading the floorplan.

Advertisements

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