XNA 4.0 中高质量输出的方法
我正在编写的应用程序中使用此示例项目的 XNA 4.0 表单控件: http://creators.xna.com/en-US/sample/winforms_series1
它运行得很好,我在视觉效果和动画方面做了很多工作。我挠头的主要问题是我渲染的 3D 模型和原始 3D 形状(镶嵌为 30 的圆柱体)有非常锯齿状的边缘,就好像它们的分辨率很低一样。
我试图弄清楚如何启用多重采样,但我可以在网上找到的所有示例似乎不适用于在自定义表单控件中使用 XNA 的这种新颖方式。
在 GraphicsDeviceService() 构造函数内创建了一个PresentationParameters 对象,但唯一可用的属性是整数类型的parameters.MultiSampleCount。我尝试过设置,但没有效果。
我还尝试将后台缓冲区设置为控件大小的两倍 (GraphicsDeviceService.cs):
GraphicsDeviceService(IntPtr windowHandle, int width, int height) { parameters.BackBufferWidth = width * 2; parameters.BackBufferHeight = height * 2; ... }
然后我更改了此函数 (GraphicsDeviceControl.cs):
void EndDraw() { Rectangle sourceRectangle = new Rectangle(0, 0, ClientSize.Width * 2, ClientSize.Height * 2); Rectangle destinationRectangle = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height); GraphicsDevice.Present(sourceRectangle, destinationRectangle, this.Handle); }
但这并没有'无法正常工作。我渲染到屏幕上的对象被降级到窗口的 1/4 并被剪裁。不过,它看起来锯齿状确实稍微少了一些...
因此,此时我不确定如何使用此方法(窗口中的 XNA 控件)来获得高质量的图形。总的来说,我对 XNA 还很陌生,所以任何建议都会非常有帮助。
I'm using this example project's XNA 4.0 form control in an application I'm writing:
http://creators.xna.com/en-US/sample/winforms_series1
It's working great and I've done quite a bit with visuals and animation. The main issue I'm scratching my head at is the 3d model and primitive 3D shapes (cylinders with a tessellation of 30) I render have very jagged edges to them as if they are low resolution.
I tried to figure out how to enable multisampling, but all of the examples I can find online don't seem to apply to this novel way of using XNA in the custom form control.
Inside the GraphicsDeviceService() constructor there is a PresentationParameters object created, but the only property available is parameters.MultiSampleCount of type integer. I tried setting that with no effect.
I also attempted making the back-buffer twice as large as the control's size (GraphicsDeviceService.cs):
GraphicsDeviceService(IntPtr windowHandle, int width, int height) { parameters.BackBufferWidth = width * 2; parameters.BackBufferHeight = height * 2; ... }
Then I changed this function (GraphicsDeviceControl.cs):
void EndDraw() { Rectangle sourceRectangle = new Rectangle(0, 0, ClientSize.Width * 2, ClientSize.Height * 2); Rectangle destinationRectangle = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height); GraphicsDevice.Present(sourceRectangle, destinationRectangle, this.Handle); }
But that didn't work properly. My objects rendered to the screen were relegated to 1/4th of the window and clipped. It did look slightly less jagged though...
So at this point I'm not sure what I can do to get high quality graphics using this method (XNA control in a window). I'm pretty new to XNA in general, so any suggestions would be most helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我下载了该代码示例以查看在何处设置了PresentationParameters。这些是你需要修改的。
它位于 GraphicsDeviceService 类中。
在该类的构造函数中,它设置了一个名为“parameters”的对象,即PresentationParamters 对象。在 new 之后和将参数传递给graphicsDevice 之前添加此行:
我任意选择的值。它提供了健康的抗锯齿功能。如果您需要了解这个数字到底是什么,请阅读有关抗锯齿的更多信息。它是通过抗混叠滤波器的次数。因此,您可能希望降低它以获得更好的性能,或者提高它以获得更好的抗锯齿效果。
I downloaded that code sample to see where the PresentationParameters were being set up. These are what you need to modify.
It's in the GraphicsDeviceService class.
In the constructor of this class, it is setting up an object called "parameters", a PresentationParamters object. Add this line after the new and before passing the parameters to the graphicsDevice:
That value I picked arbitrarily. It provides a healthy antialiasing. Read more about antialiasing if you need to understand what this number exactly is. It's the number of passes through the antialias filter. So you may want to lower it for better performance, or raise it for more antialiasing.
您可以设置 GraphicsDeviceManager 的一些属性,请确保它们全部完成。
There are a few properties of the GraphicsDeviceManager that you can set, make sure they are all done.
我遇到了这个确切的问题。如果您在 Windows 窗体中使用 XNA 图形设备控制对象,则仅设置多重采样计数将不起作用。您必须修改初始化部分中的GraphicsDeviceService.cs。
查找此初始化,以便您可以在创建图形设备时而不是事后定义多重采样计数。
其他任何地方和图形设备都会忽略您的更改
I had this EXACT problem. If you are using the XNA graphicsdevicecontrol object in a windows form, simply setting multisample count won't work. You have to modify the GraphicsDeviceService.cs in the initialization portion.
Look for this initialization so you can define the multisample count when you create your graphics device and not after the fact.
Anywhere else and the graphics device will ignore your changes