Hello
I have a multi-texture square vertex composed of four different .png files.
I blending them with“Alpha Blendig”.
g_pQuad[0].colDiffuse = D3DCOLOR_ARGB(10, 255, 255, 255);
g_pQuad[0].rhw = 1;
g_pQuad[0].vPos = D3DXVECTOR3(0 , 0 , 0);
g_pQuad[0].vUV1 = D3DXVECTOR2(0.0f, 0.0f);
g_pQuad[0].vUV2 = D3DXVECTOR2(0.0f, 0.0f);
g_pQuad[0].vUV3 = D3DXVECTOR2(0.0f, 0.0f);
g_pQuad[0].vUV4 = D3DXVECTOR2(0.0f, 0.0f);
g_pQuad[1].colDiffuse = D3DCOLOR_ARGB(10, 255, 255, 255);
g_pQuad[1].rhw = 1;
g_pQuad[1].vPos = D3DXVECTOR3(0 , 1000 , 0);
g_pQuad[1].vUV1 = D3DXVECTOR2(0.0f, 1.0f);
g_pQuad[1].vUV2 = D3DXVECTOR2(0.0f, 1.0f);
g_pQuad[1].vUV3 = D3DXVECTOR2(0.0f, 1.0f);
g_pQuad[1].vUV4 = D3DXVECTOR2(0.0f, 1.0f);
g_pQuad[2].colDiffuse = D3DCOLOR_ARGB(10, 255, 255, 255);
g_pQuad[2].rhw = 1;
g_pQuad[2].vPos = D3DXVECTOR3(1000, 0 , 0);
g_pQuad[2].vUV1 = D3DXVECTOR2(1.0f, 0.0f);
g_pQuad[2].vUV2 = D3DXVECTOR2(1.0f, 0.0f);
g_pQuad[2].vUV3 = D3DXVECTOR2(1.0f, 0.0f);
g_pQuad[2].vUV4 = D3DXVECTOR2(1.0f, 0.0f);
g_pQuad[3].colDiffuse = D3DCOLOR_ARGB(10, 255, 255, 255);
g_pQuad[3].rhw = 1;
g_pQuad[3].vPos = D3DXVECTOR3(1000, 1000 , 0);
g_pQuad[3].vUV1 = D3DXVECTOR2(1.0f, 1.0f);
g_pQuad[3].vUV2 = D3DXVECTOR2(1.0f, 1.0f);
g_pQuad[3].vUV3 = D3DXVECTOR2(1.0f, 1.0f);
g_pQuad[3].vUV4 = D3DXVECTOR2(1.0f, 1.0f);
bool MyD3DClass::InitD3D(HWND hWnd)
{
HRESULT Res;
if ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
{
return false;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
if (FAILED(Res = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice)))
{
return false;
}
g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
for(unsigned i = 0;i < 8;++i)
{
g_pd3dDevice->SetSamplerState(i,D3DSAMP_MINFILTER,D3DTEXF_LINEAR);
g_pd3dDevice->SetSamplerState(i,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR);
g_pd3dDevice->SetSamplerState(i,D3DSAMP_MIPFILTER,D3DTEXF_ANISOTROPIC);
}
g_pd3dDevice->SetTextureStageState(0,D3DTSS_TEXCOORDINDEX,0);
g_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
g_pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1);
g_pd3dDevice->SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,1);
g_pd3dDevice->SetTextureStageState(1,D3DTSS_COLORARG1,D3DTA_TEXTURE);
g_pd3dDevice->SetTextureStageState(1,D3DTSS_COLORARG2,D3DTA_CURRENT);
g_pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_MODULATE);
g_pd3dDevice->SetTextureStageState(1,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
g_pd3dDevice->SetTextureStageState(1,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
g_pd3dDevice->SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
g_pd3dDevice->SetTextureStageState(2,D3DTSS_TEXCOORDINDEX,2);
g_pd3dDevice->SetTextureStageState(2,D3DTSS_COLORARG1,D3DTA_TEXTURE);
g_pd3dDevice->SetTextureStageState(2,D3DTSS_COLORARG2,D3DTA_CURRENT);
g_pd3dDevice->SetTextureStageState(2,D3DTSS_COLOROP,D3DTOP_MODULATE);
g_pd3dDevice->SetTextureStageState(2,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
g_pd3dDevice->SetTextureStageState(2,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
g_pd3dDevice->SetTextureStageState(2,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
g_pd3dDevice->SetTextureStageState(3,D3DTSS_TEXCOORDINDEX,3);
g_pd3dDevice->SetTextureStageState(3,D3DTSS_COLORARG1,D3DTA_TEXTURE);
g_pd3dDevice->SetTextureStageState(3,D3DTSS_COLORARG2,D3DTA_CURRENT);
g_pd3dDevice->SetTextureStageState(3,D3DTSS_COLOROP,D3DTOP_MODULATE);
g_pd3dDevice->SetTextureStageState(3,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
g_pd3dDevice->SetTextureStageState(3,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
g_pd3dDevice->SetTextureStageState(3,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
return true;
}
I want to draw a variable length line on this surface. Drawing of line is triggered by mouse move event and the line connects a predefined point on the surface to the current mouse position.
I know that it is possible to redraw the background to clear the trace of the old line and then draw a new line but I want to use a different method being independent from the background texture.
In a word,I want to do this work like the draw line in the “paint”,I don’t want to have to call setTexture() or clear() functions again.how I can do this?
Regards from your help.
[EDIT] Added <pre> tags around code sniplet for better readability - Code-o-mat [/EDIT]