窗口中的 XNA 4.0 有锯齿状边缘问题...知道高质量输出的方法吗? [英] XNA 4.0 in a window having jagged edges issues...Know of a method for high quality output?

查看:18
本文介绍了窗口中的 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 = 宽度 * 2;parameters.BackBufferHeight = 高度 * 2;...}

然后我改变了这个函数(GraphicsDeviceControl.cs):

<前>void EndDraw(){矩形 sourceRectangle = new Rectangle(0, 0, ClientSize.Width * 2, ClientSize.Height * 2);矩形destinationRectangle = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height);GraphicsDevice.Present(sourceRectangle, destinationRectangle, this.Handle);}

但这并没有正常工作.我渲染到屏幕上的对象被降级到窗口的 1/4 并被剪裁.不过,它看起来确实不那么锯齿状...

所以在这一点上,我不确定如何使用这种方法(窗口中的 XNA 控件)获得高质量的图形.总的来说,我对 XNA 还是很陌生,所以任何建议都会最有帮助.

谢谢

解决方案

我下载了该代码示例以查看 PresentationParameters 的设置位置.这些是您需要修改的内容.

它在 GraphicsDeviceService 类中.

在这个类的构造函数中,正在设置一个叫做参数"的对象,一个PresentationParamters对象.在 new 之后和将参数传递给 graphicsDevice 之前添加这一行:

parameters.MultiSampleCount = 10;

我随意选择的那个值.它提供了健康的抗锯齿.如果您需要了解这个数字究竟是什么,请阅读有关抗锯齿的更多信息.它是通过抗混叠滤波器的次数.因此,您可能希望降低它以获得更好的性能,或者提高它以获得更多的抗锯齿.

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.

Thanks

解决方案

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:

parameters.MultiSampleCount = 10;

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.

这篇关于窗口中的 XNA 4.0 有锯齿状边缘问题...知道高质量输出的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆