Original Post
I am rendering particles and I want them to fade out as time progresses, so I am using the diffuse component of the color as the alpha. However, D3D seems to be ignoring me and renders the particles for one frame, then nothing at all. The alpha value is always 255, yet it seems to ignore it and render nothing instead. Here''s my code:
void RenderParticles()
{
g_pD3DDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
g_pD3DDevice->SetRenderState(D3DRS_POINTSCALEENABLE, TRUE);
g_pD3DDevice->SetRenderState(D3DRS_POINTSIZE, FtoDW(m_aParticles->m_fSize));
g_pD3DDevice->SetRenderState(D3DRS_POINTSIZE_MAX, FtoDW(1000.0f));
g_pD3DDevice->SetRenderState(D3DRS_POINTSIZE_MIN, FtoDW(0.0005f));
g_pD3DDevice->SetRenderState(D3DRS_POINTSCALE_A, FtoDW(0.0f));
g_pD3DDevice->SetRenderState(D3DRS_POINTSCALE_B, FtoDW(0.0f));
g_pD3DDevice->SetRenderState(D3DRS_POINTSCALE_C, FtoDW(1.0f));
// **********THE PROBLEM IS HERE
// Set the texture stages (this is what isn''t working)
// Setting both the color and alpha arg to D3DTA_TEXTURE results in the particles rendering, but it won''t render as it is
g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
g_pD3DDevice->SetFVF(PARTICLEFVF);
g_pD3DDevice->SetStreamSource(0, m_vbParticles, 0, sizeof(PARTICLEVERTEX));
g_pD3DDevice->SetTexture(0, m_texParticle);
// Ignore the rest of this function, it probably isn''t important - I''m just rendering the particles
PARTICLEVERTEX *pVertices;
if(FAILED(m_vbParticles->Lock(0, m_iVBSize * sizeof(PARTICLEVERTEX),
(void**)&pVertices, D3DLOCK_DISCARD)))
return E_FAIL;
int iParticlesToRender = 0;
for(int i = 0; i < m_iMaxCount; i++)
{
if(m_aParticles[i].m_bExists)
{
CParticle* pPart = &m_aParticles[i];
pVertices->vPos = pPart->m_vPos;
pVertices->color = pPart->m_Color;
pVertices++;
iParticlesToRender++;
if(iParticlesToRender == m_iVBSize)
{
m_vbParticles->Unlock();
if(FAILED(g_pD3DDevice->DrawPrimitive(D3DPT_POINTLIST, 0,
iParticlesToRender)))
return E_FAIL;
if(FAILED(m_vbParticles->Lock(0, m_iVBSize * sizeof(PARTICLEVERTEX),
(void**)&pVertices, D3DLOCK_DISCARD)))
return E_FAIL;
iParticlesToRender = 0;
}
}
}
m_vbParticles->Unlock();
if(iParticlesToRender)
{
if(FAILED(g_pD3DDevice->DrawPrimitive(D3DPT_POINTLIST, 0, iParticlesToRender)))
return E_FAIL;
}
g_pD3DDevice->SetTexture(0, NULL);
g_pD3DDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_POINTSCALEENABLE, FALSE);
}
void Render()
{
// doing stuff here
g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
RenderParticles();
g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
// doing more stuff here
}
I''m stumped. Any ideas?