XNA SpriteFont???

Sep 9, 2007 at 3:47 PM

Why you don't use SpriteFont from XNA framework?

You are making a very good work.
Sep 10, 2007 at 12:23 PM
I have converted the project to use the XNA Refresh SpriteFont, but it's in a private branch at the moment. Using it required making changes to the way the GUI is drawn, and I'm getting some serious performance problems. Expect support to be added in the next release.
Sep 10, 2007 at 7:40 PM

The problem is because of drawing hierarchy widgets? You think about change the way of widgets are drawed?

Sorry my poor enghish.
Sep 11, 2007 at 5:01 PM
Yes the problem is that each control is drawn onto its own transparent texture, which is combined with the other child controls, to be drawn onto the parent texture. This is repeated until all the GUI has to draw are the top level window controls. This method offers several advantages:

  1. Children are automatically clipped inside of their parent control.
  2. Partial transparencies look 'correct', because only the parent texture needs its alpha value set.
  3. Controls and their parents are only drawn when absolutely necessary. This means that when moving a window around the screen, the GUI only needs to make one draw (the window texture which is already a combination of the child control textures).

Now for the problem. Anti-aliased fonts use partially transparent alpha values, so when drawing they combine their partial colour with whatever colour is underneith. Normally these colours would combine to make a fully opaque colour for the destination pixel. Transparent render targets do not behave as expected when mixing alpha values. Instead, the destination pixel will contain a multiplied alpha value. This has the unfortunate side affect of making anti-aliased fonts look almost unreadable in the GUI. I was told to try using premultiplied alpha, but none of the render states would work correctly.

Recently I rewrote the drawing code, removing the use of render targets, and simply draw all controls every frame. I came across the problem of clipping children inside the parent control. I was advised to use scissor regions, which has worked correctly, although performance has been seriously affected. The reason for this is because I have to begin() and end() the spritebatch for each control, in order for the scissor regions to work. I could do the clipping myself, but I can't think of a way of clipping text, as the draw function only takes a position parameter, not a rectangle.

So yeah, I'm trying to decide between crap text, or crap performance. I should also add, that I think the GUI text looks better when using regular fonts, without anti-aliasing.
Nov 28, 2007 at 4:31 PM
In a choice between crap text and crap performance... why not let your users decide? i.e. make it an option to select either regular fonts or anti-aliased ones, then do a check to see which one is being used when it goes to draw. If regular fonts are used, go with the performance option, and if anti-aliased ones, the quality option.

Not sure how doable this would be... I just started looking at WSX yesterday, so I'm really just pulling this out of my nether regions...
Dec 3, 2007 at 6:18 PM
I eventually put together a hybrid solution, that provides nice text and good performance. There is an explanation of how I did this on the main page, and the new drawing code is included in the latest download. I'm still not happy with the fonts created automatically by XNA, so I would suggest that people create font bitmaps manually.
Jun 15, 2008 at 8:48 AM
You can use render states to fully control how alpha blending is performed. See http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.renderstate_members.aspx . There's a combination of states for all possible cases.
Jun 17, 2008 at 11:13 AM

I'm aware of those, but never found a completely suitable set of values. I even consulted a graphics expert, and he seemed to think that it may not be possible with my system.

If you can get it working then let me know.