Alpha-Blending Texture - DX9

This is a discussion on Alpha-Blending Texture - DX9 within the Game Programming forums, part of the General Programming Boards category; Well, im trying to alphablend a texture.. which is attached to this post, basically, what im trying to do is: ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    Alpha-Blending Texture - DX9

    Well, im trying to alphablend a texture.. which is attached to this post, basically, what im trying to do is:

    Make the green transparent
    Make the grey translucent
    Make the black opaque

    So far ive managed to make the green transparent and make the grey AND black translucent..

    Heres the code i used to set the texture stages:

    Code:
    g_Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    g_Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    g_Device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
    Im trying to figure out how to make only the black opaque.. any help would be appreciated

    I also attached a picture of what it currently looks like...
    Attached Images Attached Images   
    Last edited by X PaYnE X; 11-16-2004 at 01:56 AM.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    What and where are your alpha values in that texture? Are they only on the grey part?
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    the texture was a BMP, i just converted it to PNG so i could upload it faster.. i didnt set any alpha values, since the BMP was 24 bit...

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Code:
    Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
    Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
    Device->SetTextureStageState(<stage>,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
    Black=transparent
    Grey=50 % transparent
    White=opaque

    I think it's easier than using other colors for transparency.

    But you must have an alpha channel.

    Here is how to create one from a BMP:

    1. Start DXTex or the DirectX Texture Tool.
    2. Load your bmp or your picture. DXTex supports several formats
    3. Change surface format to A8R8G8B8.
    4. File->Load onto alpha channel of this surface->Select your greyscale bmp which is your alpha channel bmp.
    5. View the preview to see if it looks good
    6. Purple is the default transparent color - all purple shaded areas are see-through areas - the transparency is determined by the purple shade.
    7. Save new file as DDS file.
    8. Load DDS file using D3DXCreateTextureFromFile();


    If you are only loading a 24-bit image then there is no way to take the alpha from the alpha channel of the image since one does not exist. By default Direct3D takes the alpha value from the material source, but this will cause your whole image to use that alpha which is not what you want.

    Here is an example of one of my sun flare textures. The first one is the actual bmp and the second one is the alpha channel.
    Last edited by VirtualAce; 11-17-2004 at 09:00 AM.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    And now the alpha.
    Last edited by VirtualAce; 11-17-2004 at 08:59 AM.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    And now the resulting image.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. d3d9 c++ texture wrapper... again...
    By yaya in forum Game Programming
    Replies: 0
    Last Post: 04-01-2009, 01:08 PM
  2. D3d Texture Wrapper == ARRRGGGGHHH
    By yaya in forum Game Programming
    Replies: 1
    Last Post: 03-25-2009, 06:41 PM
  3. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  4. Alpha blending w/o color loss
    By VirtualAce in forum Game Programming
    Replies: 37
    Last Post: 10-27-2004, 12:58 AM
  5. Alpha blending
    By SMurf in forum Game Programming
    Replies: 3
    Last Post: 08-29-2003, 06:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21