I'm trying to fade my point sprites out using alpha blending, the trouble is.. No matter what I set my alpha value to they are completely opaque. Here's my code, maybe someone can figure out why they aren't blending.
initialize...
//-----------------------------------------------------------------------------
// Name: initPointSprites()
// Desc:
//-----------------------------------------------------------------------------
void ParticleSys::initPointSprites(LPDIRECT3DDEVICE9 m_pD3DDevice)
{
//
// Load up the point sprite's texture...
//
if(FAILED(D3DXCreateTextureFromFile( m_pD3DDevice, "particle.bmp", &m_texParticle )))
LogError("<li>Unable to load particle texture.");
else
LogInfo("<li>particle.bmp loaded OK");
m_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
m_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
//
// Create a vertex bufer which can be used with point sprites...
//
m_pD3DDevice->CreateVertexBuffer( 2048 * sizeof(Vertex),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY | D3DUSAGE_POINTS,
Vertex::FVF_Flags, D3DPOOL_DEFAULT,
&m_particleVertexBuffer, NULL );
//
// If you want to know the max size that a point sprite can be set to,
// and whether or not you can change the size of point sprites in hardware
// by sending D3DFVF_PSIZE with the FVF, do this.
//
float fMaxPointSize = 0.0f;
bool bDeviceSupportsPSIZE = false;
D3DCAPS9 d3dCaps;
m_pD3DDevice->GetDeviceCaps( &d3dCaps );
fMaxPointSize = d3dCaps.MaxPointSize;
if( d3dCaps.FVFCaps & D3DFVFCAPS_PSIZE )
bDeviceSupportsPSIZE = true;
else
bDeviceSupportsPSIZE = false;
}
updating..
//-----------------------------------------------------------------------------
// Name: updatePointSprites()
// Desc:
//-----------------------------------------------------------------------------
void ParticleSys::updatePointSprites( void )
{
float SLOWEST_VEL = .001f;
//
// To repeat the sample automatically, keep track of the overall app time.
//
if(dStartAppTime == 0)
dStartAppTime = timeGetTime();
float fElpasedAppTime = (float)((timeGetTime() - dStartAppTime) * 0.001);
//
// After 5 seconds, repeat the sample by returning all the particles
// back to the origin.
//
if( fElpasedAppTime >= 5.0f )
{
for( int i = 0; i < MAX_PARTICLES; ++i )
g_particles.m_vCurPos = D3DXVECTOR3(10.0f,0.0f,0.0f);
isActive = false; // Deactivate it.
dStartAppTime = 0;
return;
}
//
// Move each particle via its velocity and elapsed frame time.
//
for( int i = 0; i < MAX_PARTICLES; ++i )
{
g_particles.m_vCurPos += g_particles.m_vCurVel;
// Slow particles down unless they're already moving at slowest velocity.
if(fabs(g_particles.m_vCurVel.x) > SLOWEST_VEL || fabs(g_particles.m_vCurVel.y) > SLOWEST_VEL || fabs(g_particles.m_vCurVel.z) > SLOWEST_VEL)
{
g_particles.m_vCurVel /= 1.01f;
}
g_particles.m_fAge += 0.001f; // Increase the particles age.
}
}
rendering..
//-----------------------------------------------------------------------------
// Name: renderPointSprites()
// Desc:
//-----------------------------------------------------------------------------
void ParticleSys::renderPointSprites( LPDIRECT3DDEVICE9 m_pD3DDevice )
{
//
// Setting D3DRS_ZWRITEENABLE to FALSE makes the Z-Buffer read-only, which
// helps remove graphical artifacts generated from rendering a list of
// particles that haven't been sorted by distance to the eye.
//
// Setting D3DRS_ALPHABLENDENABLE to TRUE allows particles, which overlap,
// to alpha blend with each other correctly.
//
m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
m_pD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
m_pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);
//
// Set up the render states for using point sprites...
//
m_pD3DDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE ); // Turn on point sprites
m_pD3DDevice->SetRenderState( D3DRS_POINTSCALEENABLE, TRUE ); // Allow sprites to be scaled with distance
m_pD3DDevice->SetRenderState( D3DRS_POINTSIZE, FtoDW(1.0) ); // Float value that specifies the size to use for point size computation in cases where point size is not specified for each vertex.
m_pD3DDevice->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(1.0f) ); // Float value that specifies the minimum size of point primitives. Point primitives are clamped to this size during rendering.
m_pD3DDevice->SetRenderState( D3DRS_POINTSCALE_A, FtoDW(0.0f) ); // Default 1.0
m_pD3DDevice->SetRenderState( D3DRS_POINTSCALE_B, FtoDW(0.0f) ); // Default 0.0
m_pD3DDevice->SetRenderState( D3DRS_POINTSCALE_C, FtoDW(1.0f) ); // Default 0.0
//
// Lock the vertex buffer, and set up our point sprites in accordance with
// our particles that we're keeping track of in our application.
//
Vertex *pPointVertices;
m_particleVertexBuffer->Lock( 0, MAX_PARTICLES * sizeof(Vertex),
(void**)&pPointVertices, D3DLOCK_DISCARD );
for( int i = 0; i < MAX_PARTICLES; ++i )
{
pPointVertices->posit = g_particles.m_vCurPos;
pPointVertices->color = g_particles.m_vColor;
pPointVertices++;
}
m_particleVertexBuffer->Unlock();
//
// Render point sprites...
//
m_pD3DDevice->SetStreamSource( 0, m_particleVertexBuffer, 0, sizeof(Vertex) );
m_pD3DDevice->SetFVF( Vertex::FVF_Flags );
m_pD3DDevice->DrawPrimitive( D3DPT_POINTLIST, 0, MAX_PARTICLES );
//
// Reset render states...
//
m_pD3DDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, FALSE );
m_pD3DDevice->SetRenderState( D3DRS_POINTSCALEENABLE, FALSE );
m_pD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
m_pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
}
I want them to fade away but they aren't fading at all! I can set my sprites alpha to any number it makes no difference.