# Drawing simple geometric figures with DrawUserPrimitives?

I'm trying to draw a simple triangle based on an array of vertex. I've been searching for a tutorial and I found a simple example on riemers but I couldn't get it to work. I think it was made for XNA 3 and it seems there were some changes to XNA 4?

Using this example:

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/The_first_triangle.php

I get this error:

Additional information: The current vertex declaration does not include all the elements required by the current vertex shader. TextureCoordinate0 is missing.

I'm not english so I'm having some trouble to understand everything.

For what I understand error is confusing because I'm trying to draw a triangle color based and not texture based and it shouldn't need a texture.

Also I saw some articles about dynamic shadows and lights and I would like to know if this is the kind of code used to do it with some tweaks like culling because I'm wondering if its heavy code for performance in real time.

    public void LoadContent()
{
playerVision = new VertexPositionColor[3];
playerVision[0].Position = new Vector3(-0.5f, -0.5f, 0f);
playerVision[0].Color = Color.Red;
playerVision[1].Position = new Vector3(0, 0.5f, 0f);
playerVision[1].Color = Color.Green;
playerVision[2].Position = new Vector3(0.5f, -0.5f, 0f);
playerVision[2].Color = Color.Yellow;
}

// comes from draw method
private void drawPlayerVision(GameTime gameTime, SpriteBatch spriteBatch)
{
effect.CurrentTechnique = effect.Techniques["Pretransformed"];
Game.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, playerVision, 0, 1, VertexPositionColor.VertexDeclaration);
}

• do you have this line: effect.CurrentTechnique = effect.Techniques["Pretransformed"]; in your code? – Vodáček Jun 29 '12 at 16:09
• no, just the code on riemers tutorial. Also I don't quite understand effects files yet... – Navy Seal Jun 29 '12 at 16:19
• try to add it before foreach in Draw method – Vodáček Jun 29 '12 at 16:27
• Additional information: This method does not accept null for this parameter. I added a new file effect and loaded on content load but do I need an effect to do this? Also forget to mention I'm working with 2D if that matters. – Navy Seal Jun 29 '12 at 16:42
• ok, then post your draw method into your question – Vodáček Jun 29 '12 at 16:43

Your problem is that effect is not sent into graphics card, you need to do this:

effect.CurrentTechnique = effect.Techniques["Pretransformed"];

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

Game.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, playerVision, 0, 1, VertexPositionColor.VertexDeclaration);
}


On first line, you must select effect technique (effect file from Riemers have more of them), then send effect to graphics card and finally draw your primitive.