XNA 4.0 in a window having jagged edges issues…Know of a method for high quality output?

空扰寡人 提交于 2019-12-13 08:08:24

问题


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


回答1:


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.




回答2:


There are a few properties of the GraphicsDeviceManager that you can set, make sure they are all done.

graphics = new GraphicsDeviceManager(<A reference to your game class>)
{
  PreferMultiSampling = true,
};

graphics.PreparingDeviceSettings += (s, e) =>
{
  e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 16;
};



回答3:


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.

GraphicsDeviceService(IntPtr windowHandle, int width, int height)

{ parameters = new PresentationParameters();

        parameters.BackBufferWidth = Math.Max(width, 1);
        parameters.BackBufferHeight = Math.Max(height, 1);
        parameters.BackBufferFormat = SurfaceFormat.Color;
        parameters.DepthStencilFormat = DepthFormat.Depth24;
        parameters.DeviceWindowHandle = windowHandle;
        parameters.PresentationInterval = PresentInterval.Immediate;
        parameters.IsFullScreen = false;
        parameters.MultiSampleCount = 10; //  <--- RIGHT HERE

        graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter,
                                            GraphicsProfile.Reach,
                                            parameters);
    }

Anywhere else and the graphics device will ignore your changes



来源:https://stackoverflow.com/questions/7425474/xna-4-0-in-a-window-having-jagged-edges-issues-know-of-a-method-for-high-quali

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!