2017-01-09 6 views
0

Ich versuche ein grünes Dreieck zu zeichnen. Ich habe es geschafft, das Dreieck zum Zeichnen zu bringen, aber es ist weiß statt grün. Hat jemand eine Idee, was das verursacht?Warum ist mein Dreieck weiß?

Hier ist mein 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); 
    } 

Antwort

1

Das Problem in deiner Draw ist. Sie wenden alle Techniken an, wenn Sie nur die aktuelle Technik anwenden müssen. Das folgende funktionierte für mich:

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); 
} 
+0

Das reparierte es. Vielen Dank – Wipie44