Sprite.Draw2D and Alphablending?

I'm trying to do alphablended sprites (not color keyed sprites), but it doesn't seems to works. I tried to load .dds with alpha channel and .bmp (32bpp, last channel should be obviously alpha, but i don't know if TextureLoader.FromFile() understand the last channel as an alpha channel).

I've put the device's renderstate at alphablendingenable = true (don't have any PS GFX card). But it doesn't seems to work. Am I missing something Maybe should I try to put some texturestage state But which value should I use

System specs:
Windows 2000 SP4
Ati 7200 AIW
Dx 9 SDK (Apr 2005 release, jun release only works on XP and above)
Visual C# 2005 (with Framework .Net beta 2)


Answer this question

Sprite.Draw2D and Alphablending?

  • Jeremy Grand

    Make sure you set the Color in your Draw to Color.White

    This will allow all channels to pass through. If you set this to 0 or black then the ARGB (0,0,0,0) will be multiplied to each pixel of your image.

    Here is some sample code: This sample draws a red line from top left to bottom right.

    Bitmap myImage = new Bitmap(100, 100);
    Graphics g = Graphics
    .FromImage(myImage);
    g.Clear(
    Color.FromArgb(0));
    //Fill background with a transparent color
    g.DrawLine(new Pen(Color
    .Red, 10),1,1,100,100);
    Texture myTexture = new Texture(device, myImage, Usage.None, Pool
    .Managed);
    Sprite sprite = new Sprite
    (device);
    sprite.Begin(
    SpriteFlags
    .AlphaBlend);
    sprite.Draw2D(myTexture,
    new Point(0, 0), 0, new Point(0, 0), Color
    .White);
    sprite.End();

    Hope this helps.

    Andrew


  • dongjunming

    So i've tested some of your suggestions:

    PNG with SpriteFlags.None: No transparency
    PNG with SpriteFlags.AlphaBlending: No image displayed (very curious, isn't it )

    I surely miss something, but I don't know what. My last experience with Direct3D was with DirectX 6 (and C++ of course). I'm a bit lost with managed DirectX :/.

  • Werner de Jong

    Try to use PNG files.  Been there done that!

    []s


  • Dan Ward

    When you call Sprite.Begin are you passing the AlphaBlend flag   If you're using the Sprite interface you don't need to touch the renderstates or texturestages yourself.

  • Sprite.Draw2D and Alphablending?