2017-01-09 51 views
0

我試圖畫一個綠色的三角形。我設法得到三角形繪製,但它是白色而不是綠色。有沒有人有一個想法是什麼造成這個?爲什麼我的三角形是白色的?

這裏是我的代碼:

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

回答

1

的問題是在你的平局。當您只需要應用當前技術時,您正在應用所有技術。做以下工作對我來說:

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

修復它。謝謝 – Wipie44

相關問題