Original Post
Hi! I have been implementing a particle system using the book: "Special Effect Game Programming with DirecX". After having converted to DirectX9 everything works correct, except changing the size and color of the particles. When I change the size of a particle the color changes instead. When I try changing the color, nothing happens. I think there might be a problem with adressing the VB correctly. I have posted some relevant code: And the render-method: I hope somebody can help me out here! Best regards, Klaser
#define D3DFVF_PARTICLE (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_PSIZE)
typedef struct
{
D3DXVECTOR3 position;
D3DCOLOR color;
float pointsize;
} VERTEX_PARTICLE;
HRESULT CParticleEmitter::Render(){
HRESULT hr;
// Sæt renderstates således at der bruges pointsprites
// setup alpha blending states
m_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE );
m_pd3dDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
m_pd3dDevice->SetRenderState(D3DRS_POINTSCALEENABLE, TRUE);
m_pd3dDevice->SetRenderState(D3DRS_POINTSIZE_MIN, FtoDW(0.00f));
m_pd3dDevice->SetRenderState(D3DRS_POINTSCALE_A, FtoDW(0.001f));
m_pd3dDevice->SetRenderState(D3DRS_POINTSCALE_B, FtoDW(0.001f));
m_pd3dDevice->SetRenderState(D3DRS_POINTSCALE_C, FtoDW(0.001f));
// Klargør vertexbufferen
m_pd3dDevice->SetStreamSource(0, m_vbParticles, 0, sizeof(VERTEX_PARTICLE) );
m_pd3dDevice->SetFVF(D3DFVF_PARTICLE);
m_pd3dDevice->SetTexture(0, m_texParticle);
VERTEX_PARTICLE *pVertices;
DWORD dwNumParticlesToRender = 0;
if(FAILED(hr = m_vbParticles->Lock(0, m_iVBSize * sizeof(VERTEX_PARTICLE), (VOID **) &pVertices, D3DLOCK_DISCARD))){
MessageBox(NULL, "Kunne ikke indlæse textur til partikel!", "Error!", MB_OK);
return(hr);
}
// Tegn hver enkelt partikle
for(int q=0; q<NUMPARTICLES; q++){
if(m_Particles.IsAlive(q)){
CParticle ∂ = m_Particles.GetAt(q);
pVertices->position = part.m_vPos;
pVertices->color = (DWORD)part.m_Color;
pVertices->pointsize = 1.0f; // IF I CHANGE THIS THE COLOR OF THE PARTICLE CHANGES INSTEAD
pVertices++;
if(++dwNumParticlesToRender == m_iVBSize){
// SÅ er vi færdige med at fylde denne del af vertexbuffer - unlock og tegn!
m_vbParticles->Unlock();
if(FAILED(hr = m_pd3dDevice->DrawPrimitive(D3DPT_POINTLIST, 0, dwNumParticlesToRender))){
return(hr);
}
if(FAILED(hr = m_vbParticles->Lock(0, m_iVBSize * sizeof(VERTEX_PARTICLE), (VOID **) &pVertices, D3DLOCK_DISCARD))){
return(hr);
}
dwNumParticlesToRender = 0;
}
}
}
// Tegn det sidste snavs
m_vbParticles->Unlock();
if(dwNumParticlesToRender){
if(FAILED(hr = m_pd3dDevice->DrawPrimitive(D3DPT_POINTLIST, 0, dwNumParticlesToRender))){
return(hr);
}
}
//Ryd op og nulstill renderstates
m_pd3dDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, FALSE);
m_pd3dDevice->SetRenderState(D3DRS_POINTSCALEENABLE, FALSE);
return(hr);
}