2012-12-01 60 views
2

我想在XNA使用自定義頂點數據來渲染一個三角形,但輸出完全搞砸:我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

修正了它。

我不得不要麼設置GDM切換到全屏模式:

graphics.IsFullScreen = true; 

或者設置的後緩衝尺寸明確:

graphics.PreferredBackBufferWidth = width; 
graphics.PreferredBackBufferWidth = height;