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

How to alpha blend sprites?

Last post 7/11/2009 10:09 PM by TordinBjorn. 10 replies.
  • 12/3/2008 7:09 PM

    How to alpha blend sprites?

    I need to draw a sprite with alpha but I don't know how and I Googled it and found little if any useful information.
  • 12/7/2008 6:36 PM In reply to

    Re: How to alpha blend sprites?

    What exactly are you trying to do? If you're using the sprite batch AlphaBlend is turn on by default (or you can explicitly set it if you want like this ->   spriteBatch.Begin(SpriteBlendMode.AlphaBlend);).

    Is there something that's not working for you? If you could describe in a little more detail what you're trying to achieve I'm sure we can get you pointed in the right direction.
  • 6/14/2009 12:25 AM In reply to

    Re: How to alpha blend sprites?

    I also am having a little confusion with alphas. I'm placing simple 3D geometry in the world and moving it around. I don't have any screen HUD things, yet I still need to do a spriteBatch.Begin() and End() in order for my 3D objects' alpha to work. I have nothing between the Begin() and End(), yet it still seems to do make the alphas work. Is there a setting I can change so I don't even need the sprite batch?
  • 6/14/2009 2:21 AM In reply to

    Re: How to alpha blend sprites?

    Captain G:
    I also am having a little confusion with alphas. I'm placing simple 3D geometry in the world and moving it around. I don't have any screen HUD things, yet I still need to do a spriteBatch.Begin() and End() in order for my 3D objects' alpha to work. I have nothing between the Begin() and End(), yet it still seems to do make the alphas work. Is there a setting I can change so I don't even need the sprite batch?


    GraphicsDevice.RenderState.AlphaBlendEnable = true;
    Game hobbyist hell-bent on coding a diabolical Matrix
  • 6/26/2009 4:58 AM In reply to

    Re: How to alpha blend sprites?

    That didn't seem to work, no matter where I put it.

    My textures are currently embedded into the .FBX files exported from 3ds max, though eventually I'd like to have the textures be coupled to the models in the code so that I can use the same texture on different models to save on memory.

    I'm sure it's apparent by now that I'm a noob at this, but any help anyone can offer is appreciated.
  • 6/26/2009 12:19 PM In reply to

    Re: How to alpha blend sprites?

    Captain G:
    That didn't seem to work, no matter where I put it.

    My textures are currently embedded into the .FBX files exported from 3ds max, though eventually I'd like to have the textures be coupled to the models in the code so that I can use the same texture on different models to save on memory.

    I'm sure it's apparent by now that I'm a noob at this, but any help anyone can offer is appreciated.


    Are you using BasicEffect to render your models? If so have you set the Alpha property on the mesh effect to some value less than 1.0f?

    Maybe also try these settings:

                    graphicsDevice.RenderState.AlphaBlendEnable = true;
                    graphicsDevice.RenderState.AlphaBlendOperation = BlendFunction.Add;
                    graphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
                    graphicsDevice.RenderState.DestinationBlend = Blend.DestinationAlpha;
                    graphicsDevice.RenderState.SeparateAlphaBlendEnabled = false;

    also try this (rather than Blend.DestinationAlpha):

                    graphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;


    Game hobbyist hell-bent on coding a diabolical Matrix
  • 7/11/2009 10:31 AM In reply to

    Re: How to alpha blend sprites?

    you have to set the blendsource desc, like this and it will work. becaus you can't just tell dx10 to use alpha when it dosent know how to blend it!


    ID3D10BlendState* g_pBlendStateNoBlend = NULL;

    D3D10_BLEND_DESC BlendState;
    ZeroMemory(&BlendState, sizeof(D3D10_BLEND_DESC));
    BlendState.BlendEnable[0] = true;
    BlendState.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
    BlendState.SrcBlend = D3D10_BLEND_SRC_ALPHA;
    BlendState.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
    BlendState.BlendOp = D3D10_BLEND_OP_ADD;
    BlendState.SrcBlendAlpha = D3D10_BLEND_ZERO;
    BlendState.DestBlendAlpha = D3D10_BLEND_ZERO;
    BlendState.BlendOpAlpha = D3D10_BLEND_OP_ADD;
    BlendState.AlphaToCoverageEnable = true;
    g_pd3dDevice->CreateBlendState(&BlendState, &g_pBlendStateNoBlend);
    float blendFactor[] = {0,0,0,0};
    UINT sampleMask   = 0xffffffff;

    g_pd3dDevice->OMSetBlendState(g_pBlendStateNoBlend, blendFactor, sampleMask);


    i hope this helps!
    Whow, thats a big memory leak...
    It sure is! and we are sinking!

    kartflygaren675@hotmail.com
  • 7/11/2009 2:54 PM In reply to

    Re: How to alpha blend sprites?

    Dude this is toatally simple. Just save it as a .png. It stores transparency.
  • 7/11/2009 3:22 PM In reply to

    Re: How to alpha blend sprites?

    that dosen't work if you haven't set the alpha blend state, since it still dosent know how to handle the alpha
    Whow, thats a big memory leak...
    It sure is! and we are sinking!

    kartflygaren675@hotmail.com
  • 7/11/2009 9:21 PM In reply to

    Re: How to alpha blend sprites?

    Why would you not have the alpha blend state set?
  • 7/11/2009 10:09 PM In reply to

    Re: How to alpha blend sprites?

    it dosent know how to render the alpha pixel, wich means, render it black or render it with the thing it is overlapping.

    Whow, thats a big memory leak...
    It sure is! and we are sinking!

    kartflygaren675@hotmail.com
Page 1 of 1 (11 items) Previous Next