Hi,
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->SetDepthStencilSurface(NULL);
pDxDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f, 0.0f, 0.0, 0.0f), 1.0f, 0);
pDxDevice->BeginScene();
pSprite->Begin(D3DXSPRITE_ALPHABLEND);
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?
pSprite->End();
pDxDevice->EndScene();
}
}
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->SetTransform(&mMat);
pSprite->Draw(pTexRenderTargetDData.pTex, NULL, NULL, NULL, 0xFFFFFFFF);
pSprite->SetTransform(&matIdentity);
}
Thank you so much in advance.