[SOLVED] Anti Aliasing

Hi all,

i create a 2D game and have some worries about anti aliasing.
I read on different posts that PreferMultiSampling = true which works fine on Xna 4.0 doesn’t work on Monogame.

I build 2 basic projects drawing a texture with rotation one under xna and one under monogame and while MSAA works fine with PreferMultiSampling = true on Xna it fails on Monogame.

On Monogame i can’t activate it in game constructor but only during initialize and the result is a clear screen, the texture is not rendered.

So my question is: does MSAA work on Monogame and if yes how ?

Thx

In your Game1 constructor, you can subscribe to the GraphicsDeviceManager.PreparingDeviceSettings event. In there, you can set graphics.PreferMultiSampling to true and set the value of graphics.GraphicsDevice.PresentationParameters.MultiSampleCount to what you want.

Thanks for your help but it doesn’t work

I suscribe to the event but
1 I can’t put graphics.GraphicsDevice.PresentationParameters.MultiSampleCount in the suscriber because the GraphicsDevice is null so i locate this instruction in initialize

2 I can’t declare graphics.ApplyChanges() in the suscriber because the event occurs before Initialize and i have a stackover flow so i locate graphics.ApplyChanges() in Initialize. I have no error but the texture remains aliased so i guess it doesn’t work.

The code

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = “Content”;
graphics.GraphicsProfile = GraphicsProfile.HiDef;
graphics.PreparingDeviceSettings += Graphics_PreparingDeviceSettings;
graphics.ApplyChanges();
}

	private void Graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
	{
		graphics.PreferMultiSampling = true;
	}
	
	protected override void Initialize()
	{
	
		GraphicsDevice.PresentationParameters.MultiSampleCount = 8;
		graphics.ApplyChanges();
		base.Initialize();
	}

My bad; try this:

private void Graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
{
    graphics.PreferMultiSampling = true;
    e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 8;
}
2 Likes

I wanted to mark the post solved and have deleted previous post by mistake.

So i confirm it works fine

Thx for your help.

Is this supposed to work for OpenGL too? I tried the same small change for my DesktopGL game but there was no difference.

EDIT: I’m using deferred rendering. Does that only work with MSAA on the render target instead of the backbuffer?

I tried my test project code in an OpenGL project, no error but it’s aliased.