Archived

This topic is now archived and is closed to further replies.

SpaceMunkee

Particles Not Displaying

Recommended Posts

SpaceMunkee    122
I''m learning DirectX 9 and wrote this little cube app. Now I''m trying to add particles to it but I can''t get them to display. I''ve checked the SetTransorm calls and I''ve walked through the code to make sure that Draw Primitive is getting called (and it is), yet I don''t get any particles displaying to the screen. Could someone who is more advanced at DirectX 9 (and perhaps very bored) take a look at my code. You can grab it at http://www.illusivestudios.com/files/cube.zip. Thanks! Doug

Share this post


Link to post
Share on other sites
SpaceMunkee    122
Nothing that I can make heads or tails of.

BTW - This is displaying/rotating/texturing the cube just fine. It's just not displaying the particles.

Here is the PreRender code:


void PSystem:reRender()
{
device->SetRenderState(D3DRS_LIGHTING, false);
device->SetRenderState(D3DRS_POINTSPRITEENABLE, true);
device->SetRenderState(D3DRS_POINTSCALEENABLE, true);
device->SetRenderState(D3DRS_POINTSIZE, FtoDW(size));
device->SetRenderState(D3DRS_POINTSIZE_MIN, FtoDW(0.0f));

// control the size of the ParticleVertex relative to distance
device->SetRenderState(D3DRS_POINTSCALE_A, FtoDW(0.0f));
device->SetRenderState(D3DRS_POINTSCALE_B, FtoDW(0.0f));
device->SetRenderState(D3DRS_POINTSCALE_C, FtoDW(1.0f));

// use alpha from texture
device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
}


and the post render code:


void PSystem:ostRender()
{
device->SetRenderState(D3DRS_LIGHTING, true);
device->SetRenderState(D3DRS_POINTSPRITEENABLE, false);
device->SetRenderState(D3DRS_POINTSCALEENABLE, false);
device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
}


Here is the render code. It's rendering in batches.


void PSystem::Render()
{
if(!particles.empty())
{
PreRender();

device->SetTexture(0, texture);
device->SetFVF(D3DFVF_PARTICLE);
device->SetStreamSource(0, vb, 0, sizeof(Particle));

// start at beginning if we're at the end of the vb
if(vbOffset >= vbSize)
vbOffset = 0;

Particle* v = 0;

vb->Lock(
vbOffset * sizeof(Particle),
vbBatchSize * sizeof(Particle),
(void**)&v,
vbOffset ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD);

DWORD numParticlesInBatch = 0;

// until all particles have been rendered
std::list::iterator i;
for(i = particles.begin(); i != particles.end(); i++)
{
if(i->isAlive)
{
// copy a batch of the living particles to the
// next vertex buffer segment
v->position = i->position;
v->color = (D3DCOLOR)i->color;
v++; // next element

// increase batch number
numParticlesInBatch++;

// is this batch full?
if(numParticlesInBatch == vbBatchSize)
{
// draw the last batch of paticles that was
// copied to the vertex buffer
vb->Unlock();
device->DrawPrimitive(
D3DPT_POINTLIST,
vbOffset,
vbBatchSize);

// while that batch is drawing, start filling the
// next batch with particles.

// move the offset to the start of the next batch
vbOffset += vbBatchSize;

// don't offset into memory that's outside the vb's
// range. if we're at the end, start at the beginning
if(vbOffset >= vbSize)
vbOffset = 0;

vb->Lock(
vbOffset * sizeof(Particle),
vbBatchSize * sizeof(Particle),
(void**)&v,
vbOffset ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD);

numParticlesInBatch = 0;
}// end if
}// endif
}// end for

vb->Unlock();

// its possible that the last batch being filled never
// got rendered because the condition
// (numParticlesInBatch == vbBatchSize) would not have
// been satisfied. We darw the last partially filled batch now
if(numParticlesInBatch)
{
device->DrawPrimitive(
D3DPT_POINTLIST,
vbOffset,
numParticlesInBatch);
}
// next block
vbOffset += vbBatchSize;
PostRender();
}// end if
}// end Render()


I can post more on request. (update, init, etc..)

Thanks!
-Doug

[edited by - SpaceMunkee on May 26, 2004 1:53:39 PM]

Share this post


Link to post
Share on other sites