I don't know how to solve your problem in DX but I do in D3D.
1. Turn alpha blending on in game.
2. Create a bitmap in a paint program of a 50% grey circle.
3. Create a mask for the bitmap which masks out the circle and save to disk. (Circle=white, other=black)
4. Fire up DX texture tool and load bitmap.
5. Change surface format to A8R8G8B8.
6. Select File->Open onto alpha channel of this texture
7. Select your mask bitmap.
8. Use blend mode: D3DRS_SRCBLEND,D3DBLEND_SRCALPHA
9. Use blend mode: D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA
10. Scale the quad to suit sprite size.
11. Render the quad using the resulting texture.
Code:
#ifndef TLVERTEX
#define TLVERTEX
#include <d3dx9h>
struct TLVertex
{
//Position
D3DXVECTOR3 Pos;
//Homogenous W - 1.0f
float RHW;
//Diffuse color
D3DCOLOR dwDiffuse;
//Texture coords
float u,v;
//Flexible Vertex Format
static const DWORD FVF;
//Various constructors
TLVertex(void):Pos(D3DXVECTOR3(0.0f,0.0f,0.0f)),RHW(1.0f),dwDiffuse(0),u(0.0f),v(0.0f) {}
TLVertex(D3DXVECTOR3 _Pos,float _u,float _v,D3DCOLOR _dwDiffuse=0):Pos(_Pos),u(_u),v(_v),dwDiffuse(_dwDiffuse) {}
TLVertex(float x,float y,float z,float _u,float _v,D3DCOLOR _dwDiffuse=0):D3DXVECTOR3(x,y,z),u(_u),v(_v),dwDiffuse(_dwDiffuse) {}
//Assignment operator
TLVertex &operator=(const TLVertex &vert)
{
Pos=vert.Pos;
RHW=vert.RHW;
dwDiffuse=vert.dwDiffuse;
u=vert.u;
v=vert.v;
FVF=vert.FVF;
return *this;
}
};
#endif
Code:
#include "CObject.h"
#include "TLVertex.h"
//Define FVF for TLVertex
const DWORD TLVertex::FVF=D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1;
void CObject::Create(IDirect3DDevice9 *pDevice,D3DXVECTOR3 Pos,float fXSize,float fYSize)
{
//Init class vars
m_pDevice=pDevice;
m_fXSize=fXSize;
m_fYSize=fYSize;
m_vPos=Pos;
//Create vertices
m_pVerts[0]=TLVertex(0.0f,0.0f,1.0f,0.0f,0.0f);
m_pVerts[1]=TLVertex(1.0f,0.0f,1.0f,1.0f,0.0f);
m_pVerts[2]=TLVertex(0.0f,1.0f,1.0f,0.0f,1.0f);
m_pVerts[3]=TLVertex(1.0f,1.0f,1.0f,1.0f,1.0f);
}
void CObject::LoadTexture(std::string File)
{
//Load and create texture
D3DXCreateTextureFromFile(m_pDevice,File.c_str(),&m_pTexture);
}
void CObject::PreRender(float fTimeDelta)
{
//Set source and dest blends
m_pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
m_pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
}
void CObject::Render(float fTimeDelta)
{
//Setup scaling matrix
D3DXMATRIX matScale;
D3DXMatrixScaling(&matScale,m_fSize.x,m_fSize.y,0.0f);
//Setup translation matrix
D3DXMATRIX matTrans;
D3DXMatrixTranslation(&matTrans,m_vPos.x,m_vPos.y,1.0f);
TLVertex Verts[4];
for (int i=0;i<4;i++)
{
//Copy source verts
Verts[i]=m_pVerts[i];
//Transform verts - scale and then translate
D3DXVec3TransformCoord(&Verts[i],&matScale,m_pVerts[i]);
Verts[i]*=matTrans;
}
//Set FVF
m_pDevice->SetFVF(TLVertex::FVF);
//Set Texture
m_pDevice->SetTexture(m_pTexture);
//Draw
m_pDevice->DrawPrimitive(D3PT_TRIANGLESTRIP,2,&Verts,sizeof(TLVERTEX));
}