Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my codes that have been copied under these lines, I first combine two images with using of<i> Alpha Blending Technique</i>, and then 12 points in various sizes are drawn over the combined images. I want to <b>draw these points transparently</b>. How it is possible?
Any help is appreciated.
Bests





#define D3DFVF_CUSTOMVERTEX (D3DFVF_DIFFUSE | D3DFVF_XYZ | D3DFVF_TEX2 )
//structures
struct D3DVERTEX
{
float fX,
fY,
fZ;
DWORD color;
float fU1,
fV1;
float fU2,
fV2;
};

#define D3DFVF_CUSTOMVERTEX2 (D3DFVF_XYZ | D3DFVF_PSIZE | D3DFVF_DIFFUSE)
//structures
struct D3DVERTEX2
{
float fX,
fY,
fZ,
fSize;
DWORD dwColor;
};


D3DVERTEX aQuad[] =
{
{-1.0f, 1.0f, 2.5f, D3DCOLOR_ARGB(255,255,255,255), 0.0f,0.0f,0.0f,0.0f},
{-1.0f, -1.0f, 2.5f, D3DCOLOR_ARGB(255,255,255,255), 0.0f,1.0f,0.0f,1.0f
{1.0f, 1.0f, 2.5f, D3DCOLOR_ARGB(255,255,255,255), 1.0f,0.0f,1.0f,0.0f
{1.0f, -1.0f, 2.5f, D3DCOLOR_ARGB(255,255,255,255), 1.0f,1.0f,1.0f,1.0f}
};


D3DVERTEX2 aPoints[] =
{
{-0.5f,0.005f,1.5f, 10.0f, D3DCOLOR_ARGB(220,255,0,0)},
{-0.5f,0.055f,1.5f, 20.0f, D3DCOLOR_ARGB(220,255,0,0)},
{-0.5f,0.55f,1.5f, 20.0f, D3DCOLOR_ARGB(220,255,0,0)},
{-0.5f,0.45f,1.5f, 20.0f, D3DCOLOR_ARGB(220,255,0,0)},
{-0.5f,0.40f,1.5f, 20.0f, D3DCOLOR_ARGB(220,255,0,0)},
{-0.5f,0.35f,1.5f, 10.0f, D3DCOLOR_ARGB(220,255,0,0)},
{-0.5f,0.30f,1.5f, 20.0f, D3DCOLOR_ARGB(220,255,0,0)},
{-0.5f,0.25f,1.5f, 20.0f, D3DCOLOR_ARGB(220,255,0,0)},
{-0.5f,0.20f,1.5f, 5.0f, D3DCOLOR_ARGB(220,255,0,0)},
{-0.5f,0.15f,1.5f, 20.0f, D3DCOLOR_ARGB(100,128,128,128)},
{-0.5f,0.10f,1.5f, 20.0f, D3DCOLOR_ARGB(255,128,128,128)},
{-0.5f,0.50f,1.5f, 5.0f, D3DCOLOR_ARGB(220,0,0,0)}
};

g_App.GetDevice()->CreateVertexBuffer(sizeof(aQuad),D3DUSAGE_WRITEONLY,D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED,&pQuadVB,NULL);
g_App.GetDevice()->CreateVertexBuffer(sizeof(aPoints),D3DUSAGE_POINTS | D3DUSAGE_WRITEONLY,D3DFVF_CUSTOMVERTEX2,D3DPOOL_MANAGED,&pPointsVB,NULL);

pPointsVB->Lock(0,sizeof(aPoints),&pData,0);
memcpy(pData,aPoints,sizeof(aPoints));
pPointsVB->Unlock();

pQuadVB->Lock(0,sizeof(aQuad),(void**)&pData,0);
memcpy(pData,aQuad,sizeof(aQuad));
pQuadVB->Unlock();
D3DXCreateTextureFromFileA(g_App.GetDevice(),"Text1.bmp",&pMap1);
D3DXCreateTextureFromFileA(g_App.GetDevice(),"Text2.bmp",&pMap2);


//////////////////////////////////////////////////////////////////////////

void CApplication::InitScene(void)
{
D3DXMatrixPerspectiveFovLH(&m_matProjection,m_fFieldOfView,m_fAspectRatio,m_fNearPlane,m_fFarPlane);
m_pDirect3DDevice->SetTransform(D3DTS_PROJECTION,&m_matProjection);
m_pDirect3DDevice->SetRenderState(D3DRS_AMBIENT,RGB(255,255,255));
m_pDirect3DDevice->SetRenderState(D3DRS_LIGHTING,false);
m_pDirect3DDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
m_pDirect3DDevice->SetRenderState(D3DRS_ZENABLE,D3DZB_FALSE);

for(unsigned i = 0;i < 8;++i)
{
m_pDirect3DDevice->SetSamplerState(i,D3DSAMP_MINFILTER,D3DTEXF_LINEAR);
m_pDirect3DDevice->SetSamplerState(i,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR);
m_pDirect3DDevice->SetSamplerState(i,D3DSAMP_MIPFILTER,D3DTEXF_ANISOTROPIC);
m_pDirect3DDevice->SetSamplerState(i,D3DSAMP_MAXANISOTROPY,m_dwAnisotropy);
}

m_pDirect3DDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE);
m_pDirect3DDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
m_pDirect3DDevice->SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,1);
m_pDirect3DDevice->SetTextureStageState(1,D3DTSS_COLORARG1,D3DTA_TEXTURE);
m_pDirect3DDevice->SetTextureStageState(1,D3DTSS_COLORARG2,D3DTA_CURRENT);
m_pDirect3DDevice->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_MODULATE);
m_pDirect3DDevice->SetTextureStageState(1,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
m_pDirect3DDevice->SetTextureStageState(1,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
m_pDirect3DDevice->SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_MODULATE);

m_pDirect3DDevice->SetTextureStageState(2,D3DTSS_TEXCOORDINDEX,2);
m_pDirect3DDevice->SetTextureStageState(2,D3DTSS_COLORARG1,D3DTA_TEXTURE);
m_pDirect3DDevice->SetTextureStageState(2,D3DTSS_COLORARG2,D3DTA_CURRENT);
m_pDirect3DDevice->SetTextureStageState(2,D3DTSS_COLOROP,D3DTOP_MODULATE);
m_pDirect3DDevice->SetTextureStageState(2,D3DTSS_COLORARG1,D3DTA_CURRENT);
m_pDirect3DDevice->SetTextureStageState(2,D3DTSS_COLOROP,D3DTOP_SELECTARG1);
m_pDirect3DDevice->SetTextureStageState(2,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
m_pDirect3DDevice->SetTextureStageState(2,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
m_pDirect3DDevice->SetTextureStageState(2,D3DTSS_ALPHAOP,D3DTOP_MODULATE);

}//InitScene

//////////////////////////////////////////////////////////////////////////////

if(g_App.CheckDevice())
{
g_App.GetDevice()->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(128,128,128),1.0f,0);
g_App.GetDevice()->BeginScene();
g_App.GetDevice()->SetTexture(0,pMap1);
g_App.GetDevice()->SetTexture(1,pMap2);

g_App.GetDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
g_App.GetDevice()->SetStreamSource(0,pQuadVB,0,sizeof(D3DVERTEX));
g_App.GetDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

g_App.GetDevice()->SetFVF(D3DFVF_CUSTOMVERTEX2);
g_App.GetDevice()->SetStreamSource(0,pPointsVB,0,sizeof(D3DVERTEX2));
g_App.GetDevice()->DrawPrimitive(D3DPT_POINTLIST,0,12);

g_App.GetDevice()->EndScene();
g_App.GetDevice()->Present(NULL,NULL,NULL,NULL);
}

}
Posted
Updated 30-Oct-11 20:58pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900