GUI System questions.

Apr 25, 2010 at 9:17 PM

Good Morning all,
A couple of questions with regards to the GUI system. I am currently attempting to introduce a video component that wraps the functionality of the XNA VideoPlayer class.

Custom GUI Factories:
After reading the documentation, forums and looking at the source, it appears that I need to create my own GUIFactory class based on the IGUIFactory. I was thinking about possibly allowing the user to choose which GUI factory to use based on a configuration file, but noticed that a number of interfaces have been removed recently and don't want to re-add something without knowing the rationale for its removal. Was IGUIFactory one of the interfaces culled in the great superfluous interface hunt of '10?

Sprite Based Fonts:
What was the rationale behind rolling a sprite based font system over using the XNA supplied font system? I'm still going over the code in the GUI project and haven't spent a whole lot of time in the Font section, but I'm assuming that there was some sort of limitation from the "native" font system? I ask because I'd like to essentially wrap the native Video Player for the GUI system, and the design decision for the font system is likely to apply for the video component.

Finally, I notice that the GUI doesn't seem to have a way to apply background images etc as you would see in a menu system. Is it the intention that the main menu for a project is a non-interactive scene with the menus overlaid?


Apr 25, 2010 at 10:28 PM

if you add the following code to your project and call it each updatem you can use the XNA fonts/sprites etc. with (as far as i know) no repercussions

private void fixThreeD()// This Function is somewhat of a mystery to me but works nicely. 
        {                       // credit to
        GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;
       GraphicsDevice.RenderState.DepthBufferEnable = false;
    GraphicsDevice.RenderState.AlphaBlendEnable = true;
    GraphicsDevice.RenderState.AlphaBlendOperation = BlendFunction.Add;
    GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
    GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
    GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = false;

    GraphicsDevice.RenderState.AlphaTestEnable = true;
    GraphicsDevice.RenderState.AlphaFunction = CompareFunction.Greater;
    GraphicsDevice.RenderState.ReferenceAlpha = 0;

    GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Clamp;
    GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Clamp;

    GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Linear;
    GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Linear;
    GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Linear;

    GraphicsDevice.SamplerStates[0].MipMapLevelOfDetailBias = 0.0f;
    GraphicsDevice.SamplerStates[0].MaxMipLevel = 0;

    GraphicsDevice.RenderState.DepthBufferEnable = true;    GraphicsDevice.RenderState.AlphaBlendEnable = false;    GraphicsDevice.RenderState.AlphaTestEnable = false;

    GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;    GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;

let me know if you have problems with this. ( you will still have to override loadcontent etc.... )

May 4, 2010 at 8:52 PM

Hmm, not exactly what I was after (more reasons behind the decisions rather than the howto) but this information will be of good use to me in a few days.

Reading the post by Shawn it seems to me that all that you would need in that function is the following (assuming that SaveStateModel.SaveState in the initial spritebatch call isn't used for bottleneck reasons)


private void fixFor3D() {

    GraphicsDevice.RenderState.DepthBufferEnable = true;
GraphicsDevice.RenderState.AlphaBlendEnable = false;
GraphicsDevice.RenderState.AlphaTestEnable = false;
// the following dependant on the 3D settings. may not need to set them
    GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;



As I read the first chunk as a list of what the SpriteBatch automagically sets prior to drawing, so no great harm in setting them manually just a few extraneous commands to run - and it does make it explicit what is done. The comment Shawn makes about the vertix, indices and shaders altering might bear further investigation.

Of course I've had a pounding heachache for the last few days so I could be very mistaken.