
You can see it, but it definitely looks wrong. I am not sure what the problem is so I'll show some of my code related to the terrain, hopefully someone here can figure it out. First off, the terrain is initialized in my LevelCreator class like so:
private static GameLevel CreateAlienPlanetLevel(Game game)
{
ContentManager Content = game.Content;
GameLevel gameLevel = new GameLevel();
// Camera and lights
AddCameras(game, ref gameLevel);
gameLevel.LightManager = new LightManager();
gameLevel.LightManager.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.1f);
gameLevel.LightManager.Add("MainLight", new PointLight(new Vector3(10000, 10000, 10000), new Vector3(0.2f, 0.2f, 0.2f)));
gameLevel.LightManager.Add("CameraLight", new PointLight(Vector3.Zero, Vector3.One));
game.Services.AddService(typeof(CameraManager), gameLevel.CameraManager);
game.Services.AddService(typeof(LightManager), gameLevel.LightManager);
// Terrain
gameLevel.Terrain = new Terrain(game);
gameLevel.Terrain.Initialize();
gameLevel.Terrain.Load(game.Content, "Terrain1", 8.0f, 1.0f);
// Terrain material
TerrainMaterial terrainMaterial = new TerrainMaterial();
terrainMaterial.LightMaterial = new LightMaterial(new Vector3(0.8f), new Vector3(0.3f), 32.0f);
terrainMaterial.DiffuseTexture1 = GetTextureMaterial(game, "Terrain1", new Vector2(40, 40));
terrainMaterial.DiffuseTexture2 = GetTextureMaterial(game, "Terrain2", new Vector2(25, 25));
terrainMaterial.DiffuseTexture3 = GetTextureMaterial(game, "Terrain3", new Vector2(15, 15));
terrainMaterial.DiffuseTexture4 = GetTextureMaterial(game, "Terrain4", Vector2.One);
terrainMaterial.AlphaMapTexture = GetTextureMaterial(game, "AlphaMap", Vector2.One);
terrainMaterial.NormalMapTexture = GetTextureMaterial(game, "Rockbump", new Vector2(128, 128));
gameLevel.Terrain.Material = terrainMaterial;
game.Services.AddService(typeof(Terrain), gameLevel.Terrain);The Load method in my Terrain class looks like this:
public void Load(ContentManager content, string heightMapFileName, float blockScale, float heightScale)
{
if (!_isInitialized)
Initialize();
// Load the height map file
Texture2D heightMapTexture = content.Load<Texture2D>(heightMapFileName);
int heightMapSize = heightMapTexture.Width * heightMapTexture.Height;
_heightMap = new Color[heightMapSize];
heightMapTexture.GetData<Color>(_heightMap);
this._vertexCountX = heightMapTexture.Width;
this._vertexCountZ = heightMapTexture.Height;
this._blockScale = blockScale;
this._heightScale = heightScale;
// Load vertex declaration once
this._vertexDeclaration = new VertexDeclaration(VertexPositionNormalTangentBinormalTexture.VertexElements);
// Generate the terrain's mesh
GenerateTerrainMesh();
_transformation = new Transformation();
// Load effect
_effect = new TerrainEffect(Game.Content.Load<Effect>(TerrainEffect.EFFECT_FILENAME));
_terrainMaterial = new TerrainMaterial();
}One of the methods I am not quite sure about is GenerateTerrainMesh, also in class Terrain. The reason I am not sure about it is because I ported the original code for it from XNA 3.0 to 4.0 and I know there are some differences there in the VertexBuffer and IndexBuffer class. Here it is:
private void GenerateTerrainMesh()
{
_numVertices = _vertexCountX * _vertexCountZ;
_numTriangles = (_vertexCountX - 1) * (_vertexCountZ - 1) * 2;
// Generate the terrain indices first
int[] indices = GenerateTerrainIndices();
// Next generate the terrain's vertices
VertexPositionNormalTangentBinormalTexture[] vertices = GenerateTerrainVertices(indices);
// Create a vertex buffer to hold all the vertices
_vertexBuffer = new VertexBuffer(GraphicsDevice, _vertexDeclaration, _numVertices, BufferUsage.WriteOnly);
_vertexBuffer.SetData<VertexPositionNormalTangentBinormalTexture>(vertices);
_indexBuffer = new IndexBuffer(GraphicsDevice, IndexElementSize.ThirtyTwoBits, _numTriangles * 3 * sizeof(int),
BufferUsage.WriteOnly);
_indexBuffer.SetData<int>(indices);
}Another method I am not sure about, for the same reason as above, is Draw:
public override void Draw(GameTime gameTime)
{
// Configure TerrainEffect
SetEffectMaterial();
// Set mesh vertex and index buffer
GraphicsDevice.SetVertexBuffers(_vertexBuffer);
GraphicsDevice.Indices = _indexBuffer;
// Loop through all effect passes
foreach (EffectPass pass in _effect.CurrentTechniquePasses)
{
pass.Apply();
// Draw the mesh
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _numVertices, 0, _numTriangles);
}
}And finally, here is how all the files for the terrain are organized in my Content folder:

So any ideas why it wouldn't display correctly?










