[英]My XNA app doesn't render correctly
I'm trying to render a triangle using custom vertex data in XNA, but the output is totally messed up: 我正在尝试使用XNA中的自定义顶点数据渲染三角形,但是输出完全混乱了:
My GPU (Radeon HD7610M) supports DX11. 我的GPU(Radeon HD7610M)支持DX11。
Either I am doing something wrong or it's my GPU drivers. 我做错了什么,或者是我的GPU驱动程序。
Here's my code: 这是我的代码:
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);
}
}
I'm fairly new to XNA. 我是XNA的新手。 Am I doing something wrong?
难道我做错了什么?
Fixed it. 修复。
I had to either set the GDM to fullscreen: 我必须将GDM设置为全屏显示:
graphics.IsFullScreen = true;
Or set the dimensions of the back buffer explicitly: 或显式设置后台缓冲区的尺寸:
graphics.PreferredBackBufferWidth = width;
graphics.PreferredBackBufferWidth = height;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.