Wipie44
Wipie44

Reputation: 13

Why is my triangle white?

I'm trying to draw a green triangle. I managed to get the triangle to draw, but it is white instead of green. Does anyone have an idea what is causing this?

Here's my code:

protected override void LoadContent()
    {
        _vertexPositionColors = new[]
{
    new VertexPositionColor(new Vector3(0, 0, 0), Color.Green),
    new VertexPositionColor(new Vector3(100, 0, 0), Color.Red),
    new VertexPositionColor(new Vector3(100, 100, 0), Color.Blue)
};
        _basicEffect = new BasicEffect(GraphicsDevice);
        _basicEffect.World = Matrix.CreateOrthographicOffCenter(
            0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, 1);
        _basicEffect.LightingEnabled = false;
        _basicEffect.VertexColorEnabled = true;
    }

protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        EffectTechnique effectTechnique = _basicEffect.Techniques[0];
        EffectPassCollection effectPassCollection = effectTechnique.Passes;
        foreach (EffectPass pass in effectPassCollection)
        {
            pass.Apply();
            GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, _vertexPositionColors, 0, 1);
        }
        base.Draw(gameTime);
    }

Upvotes: 0

Views: 244

Answers (1)

Shawn Rakowski
Shawn Rakowski

Reputation: 5714

The problem is in your Draw. The you're applying all techniques when you only need to apply the current technique. Doing the following worked for me:

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);
    _basicEffect.CurrentTechnique.Passes[0].Apply();
    GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, _vertexPositionColors, 0, 1);
    base.Draw(gameTime);
} 

Upvotes: 1

Related Questions