0
\$\begingroup\$

I have a UI manager that renders a background image and some images and buttons using BlendState.AlphaBlend. This works as intended. However, when I try and draw some text on top of it with the same BlendState, each character is encased in a black box and it looks awful. I played around a bit and found that BlendState.Additive was the only one that didn't render the black boxes. However, the text is now slightly transparent, which looks weird. I then decided to mess around with custom BlendStates, but after around 10 minutes I found that there could be over 67 million different BlendStates. Hmm. My last thought is that it could be the font that is breaking it, because I tried rendering with the Arial font and AlphaBlend worked fine. Is there a way round this using BlendStates without finding a new font?

tl;dr I can only render text either with black boxes or half transparent.

Text rendering code:

sb.Begin(samplerState: SamplerState.PointClamp, blendState: BlendState.AlphaBlend, transformMatrix: Game.Camera.GetViewMatrix());

sb.DrawString(Game.Font, text, position, color);

sb.End();

SpriteFont File (using the free Minecraftia font):

<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
  <Asset Type="Graphics:FontDescription">
    <FontName>Minecraftia</FontName>
    <Size>6</Size>
    <Spacing>0</Spacing>
    <UseKerning>true</UseKerning>
    <Style>Regular</Style>
    <DefaultCharacter>?</DefaultCharacter>
    <CharacterRegions>
      <CharacterRegion>
        <Start>&#32;</Start>
        <End>&#126;</End>
      </CharacterRegion>
    </CharacterRegions>
  </Asset>
</XnaContent>

It's a pixelly game (so I need a blocky font to avoid weird antialiasing) and I think the font is a bitmap font. Just in case that makes a difference.

Edit: I found that setting the text size (in the SpriteFont file) to anything other than it's native size fixes the problem (but also renders with antialiasing, which I don't want). Also, this problem seems to happen with other bitmap fonts (tested 'Minecraftia' and '04b03').

\$\endgroup\$
0
\$\begingroup\$

I've seen that there is a bit of a common problem people are having with anti-aliasing and spritefonts for MonoGame, but so far the only thing I've seen as a workaround is to use BMFonts and the MonoGame.Extended library:

How do I draw non-smoothed fonts in MonoGame 3.5?

http://dylanwilson.net/bmfont-rendering-with-monogame-extended

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

I submitted this as an issue to the MonoGame report and they gave me this workaround: In the Pipeline tool, select your SpriteFont and in the properties pane change the Compression mode or something (bottom option) to 'Color'. This will fix the problem but in turn it will also make the resulting XNB file considerably larger.

| improve this answer | |
\$\endgroup\$

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.