I am trying to draw some textures, for example red cube 200x200 with color - D3DCOLOR redtz = D3DCOLOR_RGBA(255, 0, 0, 100), but alpha channel is always 255. I dont know where is my mistake, im newbie in D3D. Thanks in advance. Here's my code:
void CRender::BoxFilled(float x, float y, float w, float h, DWORD color)
{
vertex V[4];
V[0].color = V[1].color = V[2].color = V[3].color = color;
V[0].z = V[1].z = V[2].z = V[3].z = 0;
V[0].rhw = V[1].rhw = V[2].rhw = V[3].rhw = 0;
V[0].x = x;
V[0].y = y;
V[1].x = x + w;
V[1].y = y;
V[2].x = x + w;
V[2].y = y + h;
V[3].x = x;
V[3].y = y + h;
unsigned short indexes[] = { 0, 1, 3, 1, 2, 3 };
m_pD3dDev->CreateVertexBuffer(4 * sizeof(vertex), D3DUSAGE_WRITEONLY, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &g_pVB, NULL);
m_pD3dDev->CreateIndexBuffer(2 * sizeof(short), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &g_pIB, NULL);
VOID* pVertices;
g_pVB->Lock(0, sizeof(V), (void**)&pVertices, 0);
memcpy(pVertices, V, sizeof(V));
g_pVB->Unlock();
VOID* pIndex;
g_pIB->Lock(0, sizeof(indexes), (void**)&pIndex, 0);
memcpy(pIndex, indexes, sizeof(indexes));
g_pIB->Unlock();
m_pD3dDev->SetTexture(0, NULL);
m_pD3dDev->SetPixelShader(NULL);
m_pD3dDev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
m_pD3dDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
m_pD3dDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
m_pD3dDev->SetStreamSource(0, g_pVB, 0, sizeof(vertex));
m_pD3dDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
m_pD3dDev->SetIndices(g_pIB);
m_pD3dDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);
g_pVB->Release();
g_pIB->Release();
}
and
void fillrgba(int x, int y, int w, int h, DWORD color)
{
D3DXVECTOR2 vLine[2];
pLine->SetWidth(w);
pLine->SetAntialias(false);
pLine->SetGLLines(true);
vLine[0].x = x + w / 2;
vLine[0].y = y;
vLine[1].x = x + w / 2;
vLine[1].y = y + h;
pLine->Begin();
pLine->Draw(vLine, 2, color);
pLine->End();
}
everytime alpha is 255