Reputation: 19
I want to draw color filled quads and also strings to screen on certain occassions. Sometimes it is better looking if the drawed rectangle is transperent. However when I draw the rectangle the alpha value seems to be ignored by DirectX 9.
For instance this is my DrawFilledBox and DrawString method:
bool DrawString(const d3dfont_s* pFont, const std::wstring& wszText, int x, int y, BYTE r, BYTE g, BYTE b, BYTE a)
{
//Draw a string on backbuffer
if ((!this->m_pDevice) || (!wszText.length()) || (!pFont))
return false;
//End drawing sprites
if (FAILED(this->m_pSpriteMgr->End()))
return false;
//Set data
RECT rect = { x, y, x, y };
D3DCOLOR d3dcColor = D3DCOLOR_ARGB(a, r, g, b);
//Calculate font rect
INT iResult = pFont->pFont->DrawText(nullptr, wszText.c_str(), (int)wszText.length(), &rect, DT_NOCLIP, d3dcColor);
//Begin drawing sprites
if (FAILED(this->m_pSpriteMgr->Begin(D3DXSPRITE_ALPHABLEND)))
return false;
return iResult != 0;
}
bool DrawFilledBox(int x, int y, int w, int h, BYTE r, BYTE g, BYTE b, BYTE a)
{
//Draw a filled box on backbuffer
if (!this->m_pDevice)
return false;
IDirect3DSurface9* pSurface = nullptr;
//End drawing sprites
if (FAILED(this->m_pSpriteMgr->End()))
return false;
//Create surface
if (FAILED(this->m_pDevice->CreateOffscreenPlainSurface(w, h, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pSurface, nullptr)))
return false;
//Fill surface with color
if (FAILED(this->m_pDevice->ColorFill(pSurface, nullptr, D3DCOLOR_ARGB(a, r, g, b)))) {
pSurface->Release();
return false;
}
//Set destination area
RECT rTargetRect;
rTargetRect.left = x;
rTargetRect.top = y;
rTargetRect.right = x + w;
rTargetRect.bottom = y + h;
//Copy surface into backbuffer at desired position
bool bResult = SUCCEEDED(this->m_pDevice->StretchRect(pSurface, nullptr, this->m_pBackBuffer, &rTargetRect, D3DTEXF_NONE));
//Release surface
pSurface->Release();
//Begin drawing sprites
if (FAILED(this->m_pSpriteMgr->Begin(D3DXSPRITE_ALPHABLEND)))
return false;
return bResult;
}
As you can see I am providing an alpha value using the D3DCOLOR_ARGB macro. However alpha seems to be simply ignored.
I googled for hours, but apparently no one has had that problem before, I cannot find any threads about that.
What am I doing wrong?
Upvotes: 0
Views: 196