XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

From MDX to XNA - Help me port this RenderState code

Last post 05-02-2008 4:59 PM by JeBuS. 2 replies.
  • 05-02-2008 6:05 AM

    From MDX to XNA - Help me port this RenderState code

    So, I've got some older MDX code that is supposed to render some quads over some other scene stuff and blend the quad's texture with the rest of the scene.  I have 2 problems.  1) I don't know all of the XNA equivalents; 2) What I'm using now in XNA doesn't blend properly (in fact, it doesn't blend at all, either it is full opaque or full transparent).

    Here's the old MDX code:
                // Set render states
    device.SetRenderState( RenderStates.ZEnable, false );
    device.SetRenderState( RenderStates.FillMode, (int)FillMode.Solid );
    device.SetRenderState( RenderStates.ZBufferWriteEnable, false );
    device.SetRenderState( RenderStates.FogEnable, false );
    device.SetRenderState( RenderStates.AlphaTestEnable, false );
    device.SetRenderState( RenderStates.AlphaBlendEnable, true );
    device.SetRenderState( RenderStates.SourceBlend, (int)Blend.SourceAlpha );
    device.SetRenderState( RenderStates.DestinationBlend, (int)Blend.InvSourceAlpha );

    // Blend alphas
    device.SetTextureState( 0, TextureStates.ColorArgument1, (int)TextureArgument.Texture );
    device.SetTextureState( 0, TextureStates.AlphaArgument1, (int)TextureArgument.Texture );
    device.SetTextureState( 0, TextureStates.AlphaArgument2, (int)TextureArgument.Diffuse );
    device.SetTextureState( 0, TextureStates.AlphaOperation, (int)TextureOperation.Modulate );

    // Set sampler states
    device.SetSamplerState( 0, SamplerStates.MinFilter, (int)Filter.Linear );
    device.SetSamplerState( 0, SamplerStates.MagFilter, (int)Filter.Linear );
    device.SetSamplerState( 0, SamplerStates.MipFilter, (int)Filter.Linear );

    Now, here's what I've figured out so far for XNA.  This results in completely transparent quads (at least, I think they're completely transparent, as with this blending combo I don't see them at all):
                Game.GraphicsDevice.RenderState.DepthBufferEnable = false;
    Game.GraphicsDevice.RenderState.FillMode = FillMode.Solid;
    Game.GraphicsDevice.RenderState.DepthBufferWriteEnable = false;
    Game.GraphicsDevice.RenderState.FogEnable = false;
    Game.GraphicsDevice.RenderState.AlphaTestEnable = false;
    Game.GraphicsDevice.RenderState.AlphaBlendEnable = true;
    Game.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
    Game.GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;

    In a variation on that, it results in visible quads, but not blended (completely opaque):
                Game.GraphicsDevice.RenderState.DepthBufferEnable = false;
    Game.GraphicsDevice.RenderState.FillMode = FillMode.Solid;
    Game.GraphicsDevice.RenderState.DepthBufferWriteEnable = false;
    Game.GraphicsDevice.RenderState.FogEnable = false;
    Game.GraphicsDevice.RenderState.AlphaTestEnable = false;
    Game.GraphicsDevice.RenderState.AlphaBlendEnable = true;
    Game.GraphicsDevice.RenderState.SourceBlend = Blend.InverseSourceAlpha;
    Game.GraphicsDevice.RenderState.DestinationBlend = Blend.SourceAlpha;

    As you can see, I don't have any XNA code for the Sampler States or the Texture Alpha blending stuff from MDX.  Any help will be appreciated.
  • 05-02-2008 8:10 AM In reply to

    Re: From MDX to XNA - Help me port this RenderState code

    Well I'm not sure if it will be helpful to you or not, but if I recall correctly, the Game State Management Sample does some alpha blending between foreground menus and the background gameplay. Perhaps you can adapt the technique used in it, but then again it might not work for your situation. Anyway, the sample is found here:

    http://creators.xna.com/education/samples.aspx

  • 05-02-2008 4:59 PM In reply to

    Re: From MDX to XNA - Help me port this RenderState code

    Turns out the RenderStates I had worked just fine.  I simply forgot a line of code when loading the texture, so it wasn't appearing properly.  I guess I should get a good night's sleep before I ask questions, since the last 2 I asked I was able to answer after sleeping on it. :-P
Page 1 of 1 (3 items) Previous Next