Thursday, 11 December 2008

XNA Terrain rendering - lesson 1

I am no XNA expert - but I thought it is time to figure out how to render a terrain. I could find no better place to start than Remiers Tutorials. If your looking for a tut, follow Riemer. This is a blog :-). I am using XNA version 3.0.

In the first step, the graphics device is initialised to a 500 x 500 view.

In the second step, the effects file is loaded and incorporated into Draw. In the draw method, Riemer uses device.Clear(Color.DarkSlateBlue). But there is a property on Game called GraphicsDevice that I am using instead. A technique in the effect file called Pretransformed is used -- but nothing is in fact drawn using this technique.

In the third step, a triangle is drawn. Now the meaning of Pretransformed becomes clear - it is used as a simple rendering method of the triangle. The technique avoids the need for a camera. The triangle is specified as a set of three vertices and rendered on the draw method.

At this point I deviated from Riemer a bit and I created a DrawableGameComponent called RiemersTriangle. Moving away from the single class approach followed in the tutorial. For the component, the VertextDeclaration cannot be done on Initialise, and I had to add an override for LoadContent and put it there. The GraphicsDevice is not available during Initialise Add the component to the Game.Components on Initialise before base.Initialise is called.

Anyhow, that concludes lesson 1 -- we have a pre-transformed triangle to show for our effort

No comments:

Post a Comment