Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DirectX9 Surfaces Transparency

DirectX9 Surfaces Transparency

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hanan888
    wrote on last edited by
    #1

    DirectX9 Surface support alpha-channel and can be loaded from .png file. How can I make them draw with transparency ?

    R 1 Reply Last reply
    0
    • H Hanan888

      DirectX9 Surface support alpha-channel and can be loaded from .png file. How can I make them draw with transparency ?

      R Offline
      R Offline
      Rajkumar R
      wrote on last edited by
      #2

      "A Microsoft® Direct3D® device is a state computer", you need to enable/set the render states for Transparency. see [Alpha Blending State ^] you need to use the D3DRS_ALPHABLENDABLE render state to enable alpha transparency blending and set the blending type.

      H 1 Reply Last reply
      0
      • R Rajkumar R

        "A Microsoft® Direct3D® device is a state computer", you need to enable/set the render states for Transparency. see [Alpha Blending State ^] you need to use the D3DRS_ALPHABLENDABLE render state to enable alpha transparency blending and set the blending type.

        H Offline
        H Offline
        Hanan888
        wrote on last edited by
        #3

        from the above link: The alpha value of a color controls its transparency. Enabling alpha blending allows colors, materials, and textures on a surface to be blended with transparency onto another surface. In my game, I just need to draw .png images with alpha, the same size they are. I've got a lot of those for drawing a complicated animation. I've got about 650 images. I find the textures interface unsuitable, because of their creation cost, and the fact they don't natively looked exactly as the images. So, I'm using D3DxCreateSurfaceFromFile() and later ID3DDevice::StretchRect() to draw on the bacbuffer surface. It seems to me like the SetRenderState() capabilities do not apply to DirectX9 surfaces. But I do guess there is some way to alpha-blend surfaces because they contain alpha-channel color.

        R 1 Reply Last reply
        0
        • H Hanan888

          from the above link: The alpha value of a color controls its transparency. Enabling alpha blending allows colors, materials, and textures on a surface to be blended with transparency onto another surface. In my game, I just need to draw .png images with alpha, the same size they are. I've got a lot of those for drawing a complicated animation. I've got about 650 images. I find the textures interface unsuitable, because of their creation cost, and the fact they don't natively looked exactly as the images. So, I'm using D3DxCreateSurfaceFromFile() and later ID3DDevice::StretchRect() to draw on the bacbuffer surface. It seems to me like the SetRenderState() capabilities do not apply to DirectX9 surfaces. But I do guess there is some way to alpha-blend surfaces because they contain alpha-channel color.

          R Offline
          R Offline
          Rajkumar R
          wrote on last edited by
          #4

          Hanan888 wrote:

          The alpha value of a color controls its transparency. Enabling alpha blending allows colors, materials, and textures on a surface to be blended with transparency onto another surface.

          have you seen "on a surface" to another surface. without enabling alpha blending state, you are not going to get transparency from Direct 3D, which doesnot do/skips any alpha blending calculation on the device.

          Hanan888 wrote:

          It seems to me like the SetRenderState() capabilities do not apply to DirectX9 surfaces

          have you tried?

          Hanan888 wrote:

          So, I'm using D3DxCreateSurfaceFromFile()

          AFAIK, D3DxCreateSurfaceFromFile is not dx9 API, may be you are using some wrapper which creates a surface and uses D3DXLoadSurfaceFromFile API.

          H 1 Reply Last reply
          0
          • R Rajkumar R

            Hanan888 wrote:

            The alpha value of a color controls its transparency. Enabling alpha blending allows colors, materials, and textures on a surface to be blended with transparency onto another surface.

            have you seen "on a surface" to another surface. without enabling alpha blending state, you are not going to get transparency from Direct 3D, which doesnot do/skips any alpha blending calculation on the device.

            Hanan888 wrote:

            It seems to me like the SetRenderState() capabilities do not apply to DirectX9 surfaces

            have you tried?

            Hanan888 wrote:

            So, I'm using D3DxCreateSurfaceFromFile()

            AFAIK, D3DxCreateSurfaceFromFile is not dx9 API, may be you are using some wrapper which creates a surface and uses D3DXLoadSurfaceFromFile API.

            H Offline
            H Offline
            Hanan888
            wrote on last edited by
            #5

            Thank you.

            Rajkumar R wrote:

            have you seen "on a surface" to another surface. without enabling alpha blending state, you are not going to get transparency from Direct 3D, which doesnot do/skips any alpha blending calculation on the device.

            I think perhaps StretchRect() doesn't go through that processing. this is what I tried:

            pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
            pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
            pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCCOLOR);
            pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&pBackBuf);
            pd3dDevice->StretchRect(sourceSurface, pSourceRect, pBackBuf,
            pRectOnBackbuffer,D3DTEXF_NONE);

            I use surfaces in the A8R8G8B8 format, load from PNG images with alpha-channels. saw no effect. This is how I create the source surfaces:

            device->CreateOffscreenPlainSurface(width,height, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
            &surface, NULL);

            Rajkumar R wrote:

            AFAIK, D3DxCreateSurfaceFromFile is not dx9 API, may be you are using some wrapper which creates a surface and uses D3DXLoadSurfaceFromFile API.

            Sorry for the typo, it's D3DXLoadSurfaceFromFile().

            R 1 Reply Last reply
            0
            • H Hanan888

              Thank you.

              Rajkumar R wrote:

              have you seen "on a surface" to another surface. without enabling alpha blending state, you are not going to get transparency from Direct 3D, which doesnot do/skips any alpha blending calculation on the device.

              I think perhaps StretchRect() doesn't go through that processing. this is what I tried:

              pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
              pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
              pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCCOLOR);
              pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&pBackBuf);
              pd3dDevice->StretchRect(sourceSurface, pSourceRect, pBackBuf,
              pRectOnBackbuffer,D3DTEXF_NONE);

              I use surfaces in the A8R8G8B8 format, load from PNG images with alpha-channels. saw no effect. This is how I create the source surfaces:

              device->CreateOffscreenPlainSurface(width,height, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
              &surface, NULL);

              Rajkumar R wrote:

              AFAIK, D3DxCreateSurfaceFromFile is not dx9 API, may be you are using some wrapper which creates a surface and uses D3DXLoadSurfaceFromFile API.

              Sorry for the typo, it's D3DXLoadSurfaceFromFile().

              R Offline
              R Offline
              Rajkumar R
              wrote on last edited by
              #6

              I think so, StretchRect replaces the surface color values without doing alpha blending, i was thinking on IDirectDrawSurface:Blt which supports that. I think you need to go to texture only (collection of surface), consider using [ID3DXSprite Interface^] which made ease displaying the 2d textures. to reduce the cost of texture creation, i think you create a single texture with only one level and load surface of that level each time using D3DXLoadSurfaceFromFile, while you can get the surface of the texture level with IDirect3DTexture9::GetSurfaceLevel

              H 1 Reply Last reply
              0
              • R Rajkumar R

                I think so, StretchRect replaces the surface color values without doing alpha blending, i was thinking on IDirectDrawSurface:Blt which supports that. I think you need to go to texture only (collection of surface), consider using [ID3DXSprite Interface^] which made ease displaying the 2d textures. to reduce the cost of texture creation, i think you create a single texture with only one level and load surface of that level each time using D3DXLoadSurfaceFromFile, while you can get the surface of the texture level with IDirect3DTexture9::GetSurfaceLevel

                H Offline
                H Offline
                Hanan888
                wrote on last edited by
                #7

                Thanks again for your help.

                Rajkumar R wrote:

                i was thinking on IDirectDrawSurface:Blt which supports that

                I don't think DirectDrawSurface support any alpha-blending. It support color-keying - setting a specific color not to be shown. Also, AFAIK DirectDrawSurface cannot be loaded from .PNG file. It seems I'm gonna use the sprite interface with textures. AFAIK, all textures must be power of 2 in size which will force me to alter the resource files. Also, with the many images I have, it's kinda slow and I'm looking for anything that speeds up the loading.

                R 1 Reply Last reply
                0
                • H Hanan888

                  Thanks again for your help.

                  Rajkumar R wrote:

                  i was thinking on IDirectDrawSurface:Blt which supports that

                  I don't think DirectDrawSurface support any alpha-blending. It support color-keying - setting a specific color not to be shown. Also, AFAIK DirectDrawSurface cannot be loaded from .PNG file. It seems I'm gonna use the sprite interface with textures. AFAIK, all textures must be power of 2 in size which will force me to alter the resource files. Also, with the many images I have, it's kinda slow and I'm looking for anything that speeds up the loading.

                  R Offline
                  R Offline
                  Rajkumar R
                  wrote on last edited by
                  #8

                  Hanan888 wrote:

                  I don't think DirectDrawSurface support any alpha-blending

                  see, [IDirectDrawSurface::Blt^] and see the DDBLT_ALPHASRC flag.

                  Hanan888 wrote:

                  Also, with the many images I have, it's kinda slow and I'm looking for anything that speeds up the loading.

                  i think you can use *.dds, which stores exactly in surface format.

                  H 1 Reply Last reply
                  0
                  • R Rajkumar R

                    Hanan888 wrote:

                    I don't think DirectDrawSurface support any alpha-blending

                    see, [IDirectDrawSurface::Blt^] and see the DDBLT_ALPHASRC flag.

                    Hanan888 wrote:

                    Also, with the many images I have, it's kinda slow and I'm looking for anything that speeds up the loading.

                    i think you can use *.dds, which stores exactly in surface format.

                    H Offline
                    H Offline
                    Hanan888
                    wrote on last edited by
                    #9

                    Rajkumar R wrote:

                    see, [IDirectDrawSurface::Blt^] and see the DDBLT_ALPHASRC flag.

                    Are you sure this applies to the latest SDK? couldn't find it in any branch of the MSDN documentation tree.

                    R 1 Reply Last reply
                    0
                    • H Hanan888

                      Rajkumar R wrote:

                      see, [IDirectDrawSurface::Blt^] and see the DDBLT_ALPHASRC flag.

                      Are you sure this applies to the latest SDK? couldn't find it in any branch of the MSDN documentation tree.

                      R Offline
                      R Offline
                      Rajkumar R
                      wrote on last edited by
                      #10

                      Hanan888 wrote:

                      Are you sure this applies to the latest SDK?

                      yep, but not in Direct3D 9(though 9 is not latest) since directdraw interfaces are outdated in direct3d9. It is used latest directshow sdk, where VMR7 is supported by this IDirectDrawSurface interfaces while VMR9 is supported by IDirect3DSurface9 interfaces. Haven't you seen this "The IDirectDrawSurface interface is exposed on DirectDrawSurface objects that are used in the DirectShow multimedia streaming APIs" in that link. you can also refer some samples in DirectShow how custom allocator are implemented to mix various video streams much similar like your requirement.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups