hi everyone,
i am trying to learn to use pointsprites for particles but i am running into some problems.
all i am trying to do for now is display one particle and go from there
but the problems i got are:
1. the particle is just shown as a blank black square even though the Texture is loaded and set correctly
2. the size of it doesnt change at all when i move the camera
Please can someone take a look at my code and tell me whats wrong with it?
Or please point me to a good tutorial about pointsprites all i can find are tutorials about particle systems but no single tutorial about how to draw just one single sprite the right way
this is what i use for FVF and custom vertex:
struct PARTICLECUSTOMVERTEX{
float x, y, z;
DWORD PSIZE;
DWORD Diffuse;
};
#define D3DFVF_PARTICLEVERTEX (D3DFVF_XYZ | D3DFVF_PSIZE | D3DFVF_DIFFUSE)
and here is my code so far
class FBSParticleSystem
{
private:
protected:
public:
FBSParticle *m_Particles;
DWORD m_NumParticles;
LPDIRECT3DVERTEXBUFFER9 m_pVB;
LPDIRECT3DTEXTURE9 m_Texture;
FBSParticleSystem(LPDIRECT3DDEVICE9 Device, DWORD NumParticles)
{
m_NumParticles = NumParticles;
m_Particles = new FBSParticle[m_NumParticles];
m_pVB = NULL;
m_Texture = NULL;
Device->CreateVertexBuffer(m_NumParticles*sizeof(PARTICLECUSTOMVERTEX), 0, D3DFVF_PARTICLEVERTEX, D3DPOOL_DEFAULT, &m_pVB, NULL);
if(FAILED(D3DXCreateTextureFromFile(Device, "2.bmp", &m_Texture))){
MessageBox(NULL, "Could not find 2.bmp", "Particle", MB_OK);
}
}
~FBSParticleSystem()
{
if(m_pVB)
m_pVB->Release();
if(m_Texture)
m_Texture->Release();
if(m_Particles)
delete [] m_Particles;
}
VOID Update(LPDIRECT3DDEVICE9 g_pd3dDevice)
{
DWORD Time = timeGetTime();
PARTICLECUSTOMVERTEX *vertices = new PARTICLECUSTOMVERTEX[m_NumParticles];
for(DWORD Counter = 0; Counter < m_NumParticles; Counter++)
{
vertices[Counter].x = 0;
vertices[Counter].y = 5;
vertices[Counter].z = 0;
}
VOID* pVertices = NULL;
m_pVB->Lock( 0, sizeof(PARTICLECUSTOMVERTEX) * m_NumParticles, (void**)&pVertices, 0 );
memcpy( pVertices, vertices, sizeof(PARTICLECUSTOMVERTEX)*m_NumParticles );
m_pVB->Unlock();
FLOAT MinSize, Scale1, Scale2, Scale3, Size;
Size = 1.0;
MinSize = Scale1 = Scale2 = 0;
Scale3 = 0.2;
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, false );
g_pd3dDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
g_pd3dDevice->SetRenderState(D3DRS_POINTSCALEENABLE, TRUE);
g_pd3dDevice->SetRenderState( D3DRS_POINTSIZE, *((DWORD*)&Size ));
g_pd3dDevice->SetRenderState(D3DRS_POINTSIZE_MIN, *((DWORD*)&MinSize));
g_pd3dDevice->SetRenderState(D3DRS_POINTSCALE_A, *((DWORD*)&Scale1));
g_pd3dDevice->SetRenderState(D3DRS_POINTSCALE_B, *((DWORD*)&Scale2));
g_pd3dDevice->SetRenderState(D3DRS_POINTSCALE_C, *((DWORD*)&Scale3));
g_pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof(PARTICLECUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_PARTICLEVERTEX );
g_pd3dDevice->SetTexture(0, m_Texture);
g_pd3dDevice->DrawPrimitive( D3DPT_POINTLIST, 0, m_NumParticles );
}
};