Time for action – utilizing Terrain.fx
1. In the
Terrain.cs
class file, add the following to theDraw()
method, right after settingCurrentTechnique
for the effect:effect.Parameters["terrainTexture1"].SetValue(terrainTexture);
2. In the
BuildVertexBuffer()
method of theTerrain
class, add the following right after the position of the vertex is set inside the loop:vertices[x + (z * width)].TextureCoordinate = new Vector2((float)x / textureScale, (float)z / textureScale);
3. Execute the program and view the textured terrain, as shown in the following screenshot:
What just happened?
We now have a simple grass texture mapped to our terrain. It is still a bit difficult to make out the features of the landscape, but they are certainly more visible than when the whole thing was just a red blob. We will come back to improving the look of our terrain in Chapter 8, Tank Battles – Ending the War.