• Advertisement

3D ID3DXSprite not blending properly on a render target

Recommended Posts


I am simply trying to draw 1 texture with full alpha, and another texture on top of it with a variable alpha.

If i draw on the screen, it is perfectly fine, however, if i do it on a rendertarget, and the second texture has 0 alpha, it will overwrite the previous alpha and leave a transparent block.

I am really desperate being trying to find out why this happens for 3 hours now.

I have attached a picture describing the issue.

It feels like it overwrites completely whats behind and draw a new completely thing, ignoring whats previously on the texture.

Here is the code on render target:

No error checking for sake of simplicity.

void CUI::Init()
    pDxDevice->CreateTexture(mTexCompSubTierBG.iWidth, mTexCompSubTierBG.iHeight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pTexRenderTarget, 0);

void CUI::PreRender()
    IDirect3DSurface9* ppSurface = NULL;
    if (pTexRenderTargetDData.pTex->GetSurfaceLevel(0, &ppSurface) == D3D_OK)
        pDxDevice->SetRenderTarget(0, ppSurface);

        pDxDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f, 0.0f, 0.0, 0.0f), 1.0f, 0);



        RECT mRect;
        CDxUtils::SetRectPlusSize(&mRect, mTexCompSubBG.iPosX, mTexCompSubBG.iPosY, mTexCompSubBG.iWidth, mTexCompSubBG.iHeight);
        pSprite->Draw(mTexCompSubBG.pTexData->pTex, &mRect, NULL, &D3DXVECTOR3(0, 0, 0), 0xFFFFFFFF);

        CDxUtils::SetRectPlusSize(&mRect, mTexCompRedeemBtn[1].iPosX, mTexCompRedeemBtn[1].iPosY, mTexCompRedeemBtn[1].iWidth, mTexCompRedeemBtn[1].iHeight);
        pSprite->Draw(mTexCompRedeemBtn[1].pTexData->pTex, &mRect, NULL, &D3DXVECTOR3(55, 240 + 2, 0), 0xFFFFFFFF);

        CDxUtils::SetRectPlusSize(&mRect, mTexCompRedeemBtn[0].iPosX, mTexCompRedeemBtn[0].iPosY, mTexCompRedeemBtn[0].iWidth, mTexCompRedeemBtn[0].iHeight); // Texture with FULL ALPHA
        pSprite->Draw(mTexCompRedeemBtn[0].pTexData->pTex, &mRect, NULL, &D3DXVECTOR3(55, 240 + 2, 0), 0x00FFFFFF); // Texture with 0 Alpha and now i have a transparent block, why does it not blend? Why is it fine if you draw on screen and not on rendertarget?


void CUI::Render()
    D3DXMATRIX mMat;
	D3DXVECTOR2 spriteCentre = D3DXVECTOR2(mTexCompSubTierBG.iWidth / 2, mTexCompSubTierBG.iHeight / 2);
	D3DXVECTOR2 trans = D3DXVECTOR2(fCurPos[0] - mTexCompSubTierBG.iWidth / 2, fCurPos[1] - mTexCompSubTierBG.iHeight / 2);
	D3DXVECTOR2 scaling(fCurScaleX, fCurScaleY);
	D3DXMatrixTransformation2D(&mMat, &spriteCentre, 0, &scaling, &spriteCentre, 0, &trans);

	pSprite->Draw(pTexRenderTargetDData.pTex, NULL, NULL, NULL, 0xFFFFFFFF);


Thank you so much in advance.


Edited by Leon84

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By _RoboCat_
      Can anyone point me into good direction how to resolve this?
      I have flat mesh made from many quads (size 1x1 each) each split into 2 triangles. (made procedural)
      What i want to achieve is : "merge" small quads into bigger ones (show on picture 01), English is not my mother language and my search got no result... maybe i just form question wrong.
      i have array[][] where i store "map" information, for now i'm looking for blobs of same value in it -> and then for each position i create 1 quad. and on end create mesh from all.
      is there any good algorithm for creating mesh between random points on same plane? less triangles better. Or "de-tesselate" this to bigger/less triangles/quads?
      Also i would like to find "edges" and create "faces" between edge points (picture 02 shows what i want to achieve).
      No need for whole code, just if someone can point me in good direction would be nice.

    • By Terry Jin
      Hi everyone! 

      I am from an indie studio that has received funding for our concept and is ready to create the next generation 2D Pokemon-inspired MMORPG called Phantasy World. This ad is for a volunteer position but hopefully will transition into something more. Our vision is to create a game that draws inspiration from the series but is dramatically different in both aesthetics and gameplay as the work would be our own.
      We are hoping that you can help us make this a reality and are looking for game developers familiar with the unreal engine and would be happy to work on a 2D top down game. Sprite artists are also welcome as we are in desperate need of talented artists! Join our discord and let's have a chat! https://discord.gg/hfDxwDX

      Here's some of our in game sprites for playable characters while moving around the game world! Hope to see you soon!

    • By Karol Plewa
      I am working on a project where I'm trying to use Forward Plus Rendering on point lights. I have a simple reflective scene with many point lights moving around it. I am using effects file (.fx) to keep my shaders in one place. I am having a problem with Compute Shader code. I cannot get it to work properly and calculate the tiles and lighting properly. 
      Is there anyone that is wishing to help me set up my compute shader?
      Thank you in advance for any replies and interest!
    • By Katie Byrne
      F.OB: Forward Operating Base is a military themed base building and resource management game.

      I am currently about 6 weeks into development. still implementing core game mechanics. The game is playable in a basic sense right now but there are no objectives or missions or anything motivating really lol. 

      I have been inspired by games such as prison architect and rimworld. both in visual style and general gameplay ideas. Here is a quick 2 minute video i put together that hopefully communicates the general feel of the game and what gameplay is like. Any feedback or criticism is welcome
      I have been keeping a development diary on my youtube channel and i hope to have more developments on this project very soon. 

      So i decided to upload the current build. hopefully get some feedback.

      Its still incredibly incomplete and poorly documented so please feel free to ask me any questions about how to do tihngs. I am working on better documentation and more intuitive interactions.

      Any feedback would be a huge help. positive or negative.


      It's just a zipped Unity build. simply unzip and run the .exe no need to install anything

      Oh yes, there will be bugs  but please let me know if you find any and i'll do my best to fix them 
  • Advertisement