龙儿今天来谈一下这个Direct的融合吧。
要说简单其实很简单,只要调用SetRenderState把blend打开就行,要说难的话可能有点难以理解它到底怎么混合。
龙儿就借用一下龙书里的一个公式
outpixel = srcpixel x srcfactor + dstpixel x dstfactor;
其中的x运算为颜色值里面各个分量相乘。例如:srcpixel = (As, Rs, Gs, Bs); srcfactor = (Af, Rf, Gf, Bf);
那他们的x运算结果为(As * Af, Rs * Rf, Gs * Gf, Bs * Bf);
而这里的srcpixel为你要画的像素。已经画好的像素为dstpixel.
srcfactor与dstfactor的话可以通过SetRenderState来设定。具体参数见帮助文档。
好吧,龙儿也不废话了,上代码吧。
m_device->Clear(0, 0, D3DCLEAR_STENCIL | D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_RGBA(0, 255, 255, 255), 1, 0);
龙儿先把destpixel设为(0, 255, 255, 255);
struct Vertex
{
float x, y, z;
// float u1, v1;
DWORD color;
Vertex(float _x, float _y, float _z, DWORD _color)//, float _u1, float _v1)
{
x = _x; y