我的XNA应用程序无法正确呈现

时间:2012-12-01 19:36:32

标签: c# windows-phone-7 xna vertex-buffer

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

enter image description here

我的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很新。我做错了吗?

1 个答案:

答案 0 :(得分:1)

修正了它。

我必须将GDM设置为全屏:

graphics.IsFullScreen = true;

或明确设置后缓冲区的尺寸:

graphics.PreferredBackBufferWidth = width;
graphics.PreferredBackBufferWidth = height;
相关问题