This project is read-only.

Enable Antialiasing

Sep 20, 2009 at 10:57 AM

Hi evreyone, I'm trying to enable antialias, but I don't get any result. Is the code wrong?

 

        protected override void SetupGraphicsDeviceManager(GraphicsDeviceManager graphics, ref RenderTargetUsage presentation)
        {
            if (graphics != null) // graphics is null when starting within a WinForms host
            {
                graphics.PreferredBackBufferWidth = 1366;
                graphics.PreferredBackBufferHeight = 768;
                graphics.PreferMultiSampling = true;
                            graphics.PreparingDeviceSettings +=
              new EventHandler<PreparingDeviceSettingsEventArgs>(
                  graphics_PreparingDeviceSettings);
            }
        }
        void graphics_PreparingDeviceSettings(object sender, 
            PreparingDeviceSettingsEventArgs e)
        {
            // Xbox 360 and most PCs support FourSamples/0 
            // (4x) and TwoSamples/0 (2x) antialiasing.
            PresentationParameters pp = 
                e.GraphicsDeviceInformation.PresentationParameters;
            GraphicsAdapter adapter = e.GraphicsDeviceInformation.Adapter;
            SurfaceFormat format = adapter.CurrentDisplayMode.Format;
            // Check for 4xAA
                pp.MultiSampleQuality = 2;
                pp.MultiSampleType =
                    MultiSampleType.FourSamples;
        }


i've got the first part from one of the tutorials included with xen and the second one from msdn.

Thanks for the help.

Sep 20, 2009 at 11:11 AM

The first part should work fine, it should enable 2x AA at a minimum. However, the antialiasing will only be enabled for the back buffer. If you are drawing to a texture (DrawTargetTexture) then this will have no effect. In such a case, you need to create the DrawTargetTexture with antialiasing.

If you don't see antialiasing in the shadow map example, then it may be an issue with your PC or video driver. Sometimes video drivers can be set to override the multisampling level specified by an application...

Also, by design, 2D elements in xen.ex.graphics2D do not benefit for antialiasing.

Sep 20, 2009 at 1:18 PM
Edited Sep 20, 2009 at 5:40 PM

The shadow sample works fine; if I set to false PreferMultiSampling I can see the difference.

Do I need lights to make AntiAlias work?

EDIT: Strange thing: if I run the game fullscreen the antialias works, maybe an issue of my graphic card. Anyway thanks for the help!