2
\$\begingroup\$

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()
    {
        effect = Game.Content.Load<Effect>("Effect1");
        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);
    }
\$\endgroup\$
9
  • \$\begingroup\$ do you have this line: effect.CurrentTechnique = effect.Techniques["Pretransformed"]; in your code? \$\endgroup\$
    – Vodáček
    Commented Jun 29, 2012 at 16:09
  • \$\begingroup\$ no, just the code on riemers tutorial. Also I don't quite understand effects files yet... \$\endgroup\$
    – Navy Seal
    Commented Jun 29, 2012 at 16:19
  • \$\begingroup\$ try to add it before foreach in Draw method \$\endgroup\$
    – Vodáček
    Commented Jun 29, 2012 at 16:27
  • \$\begingroup\$ 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. \$\endgroup\$
    – Navy Seal
    Commented Jun 29, 2012 at 16:42
  • \$\begingroup\$ ok, then post your draw method into your question \$\endgroup\$
    – Vodáček
    Commented Jun 29, 2012 at 16:43

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .