Original Post
I am trying to create a particle system for the first time. I''m copying from the particle system in the book "Special Effects Game Programming with DirectX" and changing only a very small amount to suit my specific program, but it inexplicably renders nothing. Everything but the particles render normally, but the particles don''t render at all. Nothing fails in the Render() method, so I don''t understand what''s going on. Here''s my various relevant code. I''m also using lighting if that matters. Any idea of what''s going on here?
struct PARTICLEVERTEX
{
D3DXVECTOR3 vPos;
float fSize;
D3DCOLOR color;
};
#define PARTICLEFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_PSIZE)
HRESULT Render()
{
g_pD3DDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
g_pD3DDevice->SetRenderState(D3DRS_POINTSCALEENABLE, TRUE);
g_pD3DDevice->SetRenderState(D3DRS_POINTSIZE_MIN, 0);
g_pD3DDevice->SetRenderState(D3DRS_POINTSCALE_A, 0);
g_pD3DDevice->SetRenderState(D3DRS_POINTSCALE_B, 0);
g_pD3DDevice->SetRenderState(D3DRS_POINTSCALE_C, 1);
g_pD3DDevice->SetStreamSource(0, m_vbParticles, 0, sizeof(PARTICLEVERTEX));
g_pD3DDevice->SetFVF(PARTICLEFVF);
g_pD3DDevice->SetTexture(0, m_texParticle);
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->fSize = 1.0f;
pVertices->color = D3DCOLOR_ARGB(255, 255, 255, 255);
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->SetRenderState(D3DRS_POINTSPRITEENABLE, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_POINTSCALEENABLE, FALSE);
g_pD3DDevice->SetTexture(0, NULL);
return S_OK;
}