|
3D游戏程序设计入门这本书中的八章模版Stencil Mirror例程没搞懂,就是已经在RenderScene()中draw the mirror怎么还要在
void RenderScene()
{
。。。。。。//省略了// draw the floor,// draw the walls
// draw the mirror
Device->SetMaterial(&MirrorMtrl);
Device->SetTexture(0, MirrorTex);
Device->DrawPrimitive(D3DPT_TRIANGLELIST, 18, 2);
}
怎么还要在 RenderMirror() draw the mirror 啊?我怎么去掉 RenderScene()中 的 draw the mirror 就看不到镜子啊?
void RenderMirror()
{
Device->SetRenderState(D3DRS_STENCILENABLE, true);
Device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
Device->SetRenderState(D3DRS_STENCILREF, 0x1);
Device->SetRenderState(D3DRS_STENCILMASK, 0xffffffff);
Device->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);
Device->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
Device->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
Device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE);
// disable writes to the depth and back buffers
Device->SetRenderState(D3DRS_ZWRITEENABLE, false);
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
// draw the mirror to the stencil buffer
Device->SetStreamSource(0, VB, 0, sizeof(Vertex));
Device->SetFVF(Vertex::FVF);
Device->SetMaterial(&MirrorMtrl);
Device->SetTexture(0, MirrorTex);
D3DXMATRIX I;
D3DXMatrixIdentity(&I);
Device->SetTransform(D3DTS_WORLD, &I);
Device->DrawPrimitive(D3DPT_TRIANGLELIST, 18, 2);
// re-enable depth writes
Device->SetRenderState( D3DRS_ZWRITEENABLE, true );
//下面的代码省略
}
还有就是在RenderMirror()为什么要这个样子设置啊?我去掉下面的话之后也没错误发生啊
Device->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
Device->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
还要一个就是怎么要在 RenderMirror()中 disable writes to the depth and back buffers 啊?
我去掉下面的语句运行起来好像也没错?
Device->SetRenderState(D3DRS_ZWRITEENABLE, false);
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
请各位师傅百忙之中指导一下。谢谢
[em7] [em18] |
|