2

我正在尝试使用 XNA 中的自定义顶点数据渲染三角形,但输出完全混乱:

在此处输入图像描述

我的 GPU (Radeon HD7610M) 支持 DX11。

要么我做错了什么,要么是我的 GPU 驱动程序。

这是我的代码:

public class MyGame : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    VertexBuffer vertexBuffer;
    VertexPositionColor[] vertices;
    BasicEffect effect;

    public MyGame()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
        TargetElapsedTime = TimeSpan.FromTicks(333333);
        InactiveSleepTime = TimeSpan.FromSeconds(1);
    }
    protected override void Initialize()
    {
        base.Initialize();
    }

    protected override void LoadContent()
    {
        effect = new BasicEffect(GraphicsDevice);
        effect.VertexColorEnabled = true;

        vertices = new VertexPositionColor[]
        {
            new VertexPositionColor(new Vector3(-0.8F, -0.8F, 0), Color.Black),
            new VertexPositionColor(new Vector3(-0.8F,  0.8F, 0), Color.Black),
            new VertexPositionColor(new Vector3( 0.8F, -0.8F, 0), Color.Black),
            //new VertexPositionColor(new Vector3( 0.8F,  0.8F, 0), Color.Black),
        };

        vertexBuffer = new VertexBuffer(GraphicsDevice, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
        vertexBuffer.SetData<VertexPositionColor>(vertices);
    }

    protected override void UnloadContent() {}

    protected override void Update(GameTime gameTime)
    {
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        base.Update(gameTime);
    }

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

        foreach (EffectPass pass in effect.CurrentTechnique.Passes)
        {
            pass.Apply();
            GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
        }

        base.Draw(gameTime);
    }
}

我对 XNA 很陌生。难道我做错了什么?

4

1 回答 1

1

修复。

我不得不将 GDM 设置为全屏:

graphics.IsFullScreen = true;

或显式设置后台缓冲区的尺寸:

graphics.PreferredBackBufferWidth = width;
graphics.PreferredBackBufferWidth = height;
于 2012-12-02T10:51:22.120 回答