NoPremultiply on SpriteFont

May 31, 2013 at 2:57 AM
Edited May 31, 2013 at 3:00 AM
Hello,

Great to see this quick functionality added to C++ Direct3D! The spritefonts are rendering fine, except when I use the NoPremultiply flag, the resultant spritefont will render each character as a solid fill. So if my characters are white, I will get a bunch of white rectangles where the characters should be. The debug output file seems fine, though.

Is there a certain way that I should be using fonts that are generated with the NoPremultiply flag?

I'm using the Feb 22 2013 stable release.

Thanks,
Allen
Coordinator
May 31, 2013 at 5:24 AM
Edited May 31, 2013 at 5:24 AM
When you draw the SpriteBatch that you are using to draw the text, you need to pass a different object to Begin as discussed on the SpriteBatch page under "Alpha Blending" if using 'straight' alpha rather than the default premultiplied alpha.
CommonStates states(deviceContext);

spriteBatch->Begin(SpriteSortMode_Deferred, states.NonPremultiplied() );
spriteFont->DrawString(spriteBatch.get(), L"Hello, world!", XMFLOAT2(x, y));
spriteBatch->End();
Jun 2, 2013 at 3:10 PM
Ah, thanks walbourn! Now I understand the purpose of that flag.

I guess my next question addresses what I was originally trying to do with that flog: Is there any way to generate/render without any type of anti-aliasing on larger fonts?
Coordinator
Jun 3, 2013 at 6:55 PM
You could change the MakeSpriteFont tool to generate a monochrome image. I'm not sure whether there's any way to get GDI+ to rasterize the text without AA, but it would be easy to make the tool just quantize the resulting alpha values to 0 or 0xFF.
Jul 12, 2013 at 4:03 AM
Thanks Shawn, this sounds like it should be a simple approach!

I am making an display input lag timer which requires taking photos of text rendered to the screen, and having no anti-aliasing seems to help readability. This is low on my priority list, but I will post back here when I have success with this method.