[Solved] Help with Printing Text with Nearest Neighbor Filtering

I created a basic SpriteFont (Arial, Size: 12) that I’m playing around with.
It looks fine when drawn with spriteBatch.Begin() (no parameters passed).

However, when I draw with Nearest Neighbor filtering, it’s showing up with some black areas (there’s even a black pixel underneath the comma). Increasing the font size didn’t help either:

Below is my Draw function:

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);

    spriteBatch.Begin(blendState: BlendState.Opaque, samplerState: SamplerState.PointClamp);

    spriteBatch.DrawString(gameFont, "Hello, World!", new Vector2(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2), Color.White);

    spriteBatch.End();

    base.Draw(gameTime);
}

Is there a proper way to draw SpriteFonts on the screen with Nearest Neighbor?
Am I even doing this Nearest Neighbor filtering correctly?

I intend to draw everything with Nearest Neighbor because I plan to make a simple, retro-style pixel Pong clone as my first project to familiarize myself with MonoGame.

BlendState.AlphaBlend or BlendState.NonPremultiplied?

2 Likes

spriteBatch.Begin(blendState: BlendState.AlphaBlend, samplerState: SamplerState.PointClamp); seemed to do the trick!

Any explanation as to why the issue was happening? :slightly_smiling_face:

When rendering opaque, it does not take the sprite textures alpha onto account. It has to be alpha blended.

1 Like

Ah, got it. Thanks! :slightly_smiling_face: