Welcome to this 3rd installment of my Tutorials on XNA. Because this Series will cover a lot of ground, I would like to take a jumpstart by starting from the code presented below. As you can see on the screenshot below, it will only draw a simple triangle. There is nothing in this code that hasnít been covered yet in the previous 2 series.
Starting point for the 3rd series of XNA Tutorials
At this moment, my standard effects.fx file is loaded so we are able to render the triangle, but soon my effect file will be replaced by one of your own.
Thatís about all there is to say about our starting code. If you have been following my tutorials up to this point, simply copy-paste this code into a new XNA Game Studio 4.0 project. Remember, you might have to change my namespace to yours (or vice versa). The only requirement is that both namespaces in the Game1.cs and Program.cs files are the same.
Click here to go to the forum on this chapter!
Or click on one of the topics on this chapter to go there:
Carlight not found
Hey when i tried to download the carlight.jpg file...Effect Files
Hi,I have read your codes
But I found I can not f...Drawing Primitives
Got time today to start reading the thi...2.0 anyone?
Could someone please upload xna 2.0 code for this ...problem with ResourceUsage.WriteOnly
"ResourceUsage.WriteOnly" was working before in ...I have found a Lamppost
Itīs not Texturen but colored
http://reinerstil...Textures applied wrong
Just wondering why the textures are a...Load effect file
In this series you loaded the effect file with the...PreparingDeviceSettings??
I didnt understand what exactly does this line doe...
public class Game1 : Microsoft.Xna.Framework.Game
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
protected override void Initialize()
graphics.PreferredBackBufferWidth = 500;
graphics.PreferredBackBufferHeight = 500;
graphics.IsFullScreen = false;
Window.Title = "Riemer's XNA Tutorials -- Series 3";
protected override void LoadContent()
device = GraphicsDevice;
effect = Content.Load<Effect>
("effects"); SetUpVertices(); SetUpCamera();
private void SetUpVertices()
VertexPositionColor vertices = new VertexPositionColor;
vertices = new VertexPositionColor(new Vector3(-2, 2, 0), Color.Red);
vertices = new VertexPositionColor(new Vector3(2, -2, -2), Color.Green);
vertices = new VertexPositionColor(new Vector3(0, 0, 2), Color.Yellow);
vertexBuffer = new VertexBuffer(device, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
private void SetUpCamera()
cameraPos = new Vector3(0, 5, 6);
viewMatrix = Matrix.CreateLookAt(cameraPos, new Vector3(0, 0, 1), new Vector3(0, 1, 0));
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 1.0f, 200.0f);
protected override void UnloadContent()
protected override void Update(GameTime gameTime)
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
protected override void Draw(GameTime gameTime)
device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.DarkSlateBlue, 1.0f, 0);
effect.CurrentTechnique = effect.Techniques["ColoredNoShading"];
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
- Website design & XNA + DirectX code : Riemer Grootjans -
©2003 - 2011 Riemer Grootjans