【问题标题】:Why is my triangle white?为什么我的三角形是白色的?
【发布时间】:2017-01-09 16:00:23
【问题描述】:

我正在尝试绘制一个绿色三角形。我设法绘制了三角形,但它是白色而不是绿色。有谁知道是什么原因造成的?

这是我的代码:

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

【问题讨论】:

    标签: c# xna 2d monogame


    【解决方案1】:

    问题出在你的 Draw 中。当您只需要应用当前技术时,您正在应用所有技术。执行以下操作对我有用:

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

    【讨论】:

    • 修复了它。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 2013-11-08
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多