Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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);
    }
share|improve this question
    
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

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.