Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用RenderTarget2D会导致模糊_C#_Xna_Rendertarget - Fatal编程技术网

C# 使用RenderTarget2D会导致模糊

C# 使用RenderTarget2D会导致模糊,c#,xna,rendertarget,C#,Xna,Rendertarget,如果我只是这样做,我会收到一个正常绘制的模型: GraphicsDevice.Clear(Color.Black); GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.DepthStencilState = DepthStencilState.Default; DrawModel(model, modelMatrix, transforms); 但是,如果我尝试使用渲染目标,即使没有对其应用任何效果,结果也会非常模糊:

如果我只是这样做,我会收到一个正常绘制的模型:

GraphicsDevice.Clear(Color.Black);
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
DrawModel(model, modelMatrix, transforms);
但是,如果我尝试使用渲染目标,即使没有对其应用任何效果,结果也会非常模糊:

GraphicsDevice.SetRenderTarget(scene);
GraphicsDevice.Clear(Color.Black);
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
DrawModel(model, modelMatrix, transforms);
GraphicsDevice.SetRenderTarget(null);

spriteBatch.Begin();
spriteBatch.Draw(scene, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
spriteBatch.End();
唯一的区别是使用渲染目标。左侧为法线图形,右侧为渲染目标图形。以下是渲染目标的定义方式:

scene = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);
我也尝试过这样定义它:

scene = new RenderTarget2D(device, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, false, device.DisplayMode.Format, DepthFormat.Depth24, 0, RenderTargetUsage.PlatformContents);

我在这里做错了什么?

确保使用与BackBuffer相同的设置

有许多选项需要注意,但我不记得在使用RenderTarget2D时遇到过问题

试着用这个(我就是这么用的,对我来说很好):


您是否尝试过禁用精灵上的过滤功能?这可以通过Begin方法的重载来完成,并为相应的参数提供samplestate.PointClamp。我认为这实际上可能看起来更糟-它现在严重像素化和模糊。您是否确保渲染目标的大小与BackBuffer的大小完全相同?如果两者大小相同,PointClamp实际上应该修复它。另外,你是否意识到这一点?这很难做到,但请尝试查看是否有更改。确保使用与BackBuffer相同的设置。有许多选项需要注意,但我不记得在使用RenderTarget2D时遇到过问题。尝试使用新的RenderTarget2D(GraphicsDevice、pixelWidth、pixelHeight、false、SurfaceFormat.Bgr565、DepthFormat.Depth24Stencil8)这是我用的。
new RenderTarget2D(GraphicsDevice, pixelWidth, pixelHeight, false, SurfaceFormat.Bgr565, DepthFormat.Depth24Stencil8);