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> </Start> <End>~</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').