Original Post
I''m currently working on a particle system, but I''m having trouble getting my particles to render. I''ve looked at the point sprites demo, and I think I''m doing all the required steps, but so far no joy. Heres my code for my vertex structure, FVF & render function:
Any help is appreciated.
Steve.
#define D3DFVF_PARTICLEFVF ( D3DFVF_XYZ | D3DFVF_DIFFUSE )
struct PARTICLEVERTEX
{
float x, y, z;
D3DCOLOR DiffuseColor;
};
Render()
{
// Set the render state for drawing particles
g_pDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
g_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
g_pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
g_pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
// Set the render states for using point sprites
g_pDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );
g_pDevice->SetRenderState( D3DRS_POINTSCALEENABLE, TRUE );
g_pDevice->SetRenderState( D3DRS_POINTSIZE, 0.08f );
g_pDevice->SetRenderState( D3DRS_POINTSIZE_MIN, 5.00f );
g_pDevice->SetRenderState( D3DRS_POINTSCALE_A, 0.00f );
g_pDevice->SetRenderState( D3DRS_POINTSCALE_B, 0.00f );
g_pDevice->SetRenderState( D3DRS_POINTSCALE_C, 1.00f );
// Create the vertex buffer
LPDIRECT3DVERTEXBUFFER8 m_pVB = 0;
g_pDevice->CreateVertexBuffer( sizeof(PARTICLEVERTEX),
D3DUSAGE_DYNAMIC | D3DUSAGE_POINTS,
D3DFVF_PARTICLEFVF, D3DPOOL_DEFAULT, &m_pVB );
// Lock into vertex buffer
BYTE* pVBData = 0;
m_pVB->Lock( 0, sizeof( PARTICLEVERTEX ), &pVBData, 0 );
// Copy the data into the vertex buffer
CopyMemory( pVBData, &m_Particle.m_Vertex,
sizeof( m_Particle.m_Vertex ) );
// Unlock the vertex buffer
m_pVB->Unlock();
// Set up the vertex buffer to be rendered
g_pDevice->SetStreamSource( 0, m_pVB, sizeof(PARTICLEVERTEX) );
g_pDevice->SetVertexShader( D3DFVF_PARTICLEFVF );
// Render the particle system
g_pDevice->DrawPrimitive( D3DPT_POINTLIST, 0, 1);
m_pVB = 0;
// Reset render states
g_pDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, FALSE );
g_pDevice->SetRenderState( D3DRS_POINTSCALEENABLE, FALSE );
// Reset the render state
g_pDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
g_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
}