XNA 4.0 in a window that has problems with jagged edges ... Know a method for high quality output?

I am using this example XNA 4.0 format project management in the application that I am writing: http://creators.xna.com/en-US/sample/winforms_series1

It works great, and I did a little work with visual effects and animations. The main problem I am facing is the 3D model and the primitive 3D shapes (cylinders with tessellation 30) that I visualize have very jagged edges, as if they were low resolution.

I tried to figure out how to enable multisampling, but all the examples I can find on the Internet do not seem to apply to this new way of using XNA in a form user control.

A PresentationParameters object is created inside the GraphicsDeviceService () constructor, but the only parameter available is the parameter. MultipleSampleCount integer type. I tried to set this without effect.

I also tried to make the back buffer twice as large as the control 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 did not work. My objects displayed on the screen were assigned to the 1/4 window and cropped. It looked a little less jagged, though ...

So, at the moment I'm not sure what I can do to get high-quality graphics using this method (XNA control in the window). I am new to XNA in general, so any suggestions would be most helpful.

thanks

0
source share
3 answers

I downloaded this sample code to see where PresentationParameters were set. This is what you need to change.

This is in the GraphicsDeviceService class.

In the constructor of this class, it creates an object called "parameters", a PresentationParamters object. Add this line after the new one and before passing the parameters to the graphics device:

parameters.MultiSampleCount = 10; 

This value is selected arbitrarily. It provides healthy smoothing. Learn more about anti-aliasing if you need to understand what exactly this number is. This is the number of passes through the antialias filter. Therefore, you can lower it for better performance or increase it for more smoothing.

+5
source

There are several GraphicsDeviceManager properties that you can set, make sure everything is done.

 graphics = new GraphicsDeviceManager(<A reference to your game class>) { PreferMultiSampling = true, }; graphics.PreparingDeviceSettings += (s, e) => { e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 16; }; 
+2
source

I had this EXACT problem. If you use a window-shaped XNA graphicsdevicecontrol object, simply setting the number of multisamples will not work. You must change the GraphicsDeviceService.cs in the initialization part.

Look for this initialization so that you can determine the number of multisamples when creating a 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); } 

Your changes will be ignored anywhere and on your graphics device.

0
source

Source: https://habr.com/ru/post/1446655/


All Articles