Game Development Reference
In-Depth Information
preRender —Used to set initial render states that must be set
before rendering. Since this can vary from system to system, we
make it virtual. The default implementation is as follows:
void PSystem::preRender()
{
_device->SetRenderState(D3DRS_LIGHTING, false);
_device->SetRenderState(D3DRS_POINTSPRITEENABLE, true);
_device->SetRenderState(D3DRS_POINTSCALEENABLE, true);
_device->SetRenderState(D3DRS_POINTSIZE, d3d::FtoDw(_size));
_device->SetRenderState(D3DRS_POINTSIZE_MIN, d3d::FtoDw(0.0f));
// control the size of the particle relative to distance
_device->SetRenderState(D3DRS_POINTSCALE_A, d3d::FtoDw(0.0f));
_device->SetRenderState(D3DRS_POINTSCALE_B, d3d::FtoDw(0.0f));
_device->SetRenderState(D3DRS_POINTSCALE_C, d3d::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);
}
Note that we have enabled alpha blending so that the currently set
texture's alpha channel specifies the transparency of the texture's
pixels. We use this for a variety of effects; one in particular is to
obtain particles that are not rectangular shaped, as the texture is.
For instance, to obtain a round “snowball-looking” particle, we use
a plain white texture with an alpha channel that is black with a
white circle. Thus, only a round white circle will be displayed
rather than a rectangular white texture.
postRender —Used to restore any render states that a particular
particle system might have set. Since this can vary from system to
system, we make it virtual. The default implementation is as
follows:
void PSystem::postRender()
{
_device->SetRenderState(D3DRS_LIGHTING, true);
_device->SetRenderState(D3DRS_POINTSPRITEENABLE, false);
_device->SetRenderState(D3DRS_POINTSCALEENABLE, false);
_device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
}
isEmpty —True if there are no particles in the current system, and
false otherwise
Search WWH ::




Custom Search