2012-12-01 37 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;