gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:51:08 24 4
gpt4 key购买 nike

我试图在 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 的新手。我做错了什么吗?

最佳答案

已修复。

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

graphics.IsFullScreen = true;

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

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

关于c# - 我的 XNA 应用程序无法正确呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13662976/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com