Jump to content
  • Advertisement

3D ID3DXSprite not blending properly on a render target

This topic is 366 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!