4
\$\begingroup\$

I am building a game with a "low resolution" aesthetic, so I would like to disable the default font anti-aliasing. The text is drawn using the built-in SpriteFont and SpriteBatch classes.

Here is what it currently looks like:

enter image description here

Here is what I would like it to look like:

enter image description here

(Please ignore the particles)

\$\endgroup\$
5
  • \$\begingroup\$ Did you try anything? \$\endgroup\$ – Vaillancourt Jun 19 '15 at 23:18
  • \$\begingroup\$ What does the font actually look like? Are you hoping for a way to make a regular font look like the one on the bottom? If you have the text on the bottom as a font and are drawing it without re-sizing it then it should look like the text on the bottom. \$\endgroup\$ – ClassicThunder Jun 20 '15 at 0:08
  • \$\begingroup\$ The font is Arial Narrow. The bottom image was done in Photoshop by setting the smoothing to "None". \$\endgroup\$ – asafafas Jun 20 '15 at 7:43
  • \$\begingroup\$ @asafafas XNA fonts are simply images. Load the image file in photoshop, set the smoothing to none, then load it up in your content project.See web.archive.org/web/20140812180813/http://www.nubik.com/…. \$\endgroup\$ – ClassicThunder Jun 23 '15 at 17:31
  • \$\begingroup\$ Did you set the samplerstate to SamplerState.PointClamp in your SpriteBatch.Begin? \$\endgroup\$ – Felsir Jul 7 '15 at 13:58
4
\$\begingroup\$

To turn off antialiasing, all you have to do is change your sampler state to SamplerState.PointClamp in your spriteBatch.Begin() call. Here's a short code example:

spriteBatch.Begin(SpriteSortMode.Deferred,
      BlendState.AlphaBlend,
      SamplerState.PointClamp,
      null, null, null, null));

// Draw text here using DrawString

spriteBatch.End();

spriteBatch.Begin()

// Draw textures, etc

spriteBatch.End()

Alternatively to this, you can permanently set the SamplerState of the graphics device to PointClamp in your Initialize() method with the following code (this should work in any method that is only called once, maybe even the constructor):

graphicsDevice.SamplerStates[0] = SamplerState.PointClamp;

This way, you could use the normal spriteBatch.Begin() call with no parameters. Note that this method would apply SamplerState.PointClamp to everything that you draw, not just text

References:

Here's the reference for XNA's SamplerState, which should be the same as MonoGame's: https://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.samplerstate_fields%28v=xnagamestudio.40%29.aspx

Behind the scenes when actually drawing, SamplerState.PointClamp actually evaluates to:

Filter = TextureFilter.Point,

AddressU = TextureAddressMode.Clamp,
AddressV = TextureAddressMode.Clamp,
AddressW = TextureAddressMode.Clamp,

(according to the documentation)

Notes:

Another possibility to disable antialiasing would be to change this graphics device setting:

Game1.GraphicsDevice.RenderState.MultiSampleAntiAlias = false;
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Filter = TextureFilter.Point is the key line here. By default, XNA uses a Linear filter, which will interpolate colors when pixels are not one to one. Point filter will, on the other hand, just scale the pixels and do no interpolation. \$\endgroup\$ – Alexandre Desbiens Jul 7 '15 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.