Hello all.
I have tried all day to get my stencil buffer to work for a simple 2D rectangle.
What I want to accomplish is a simple 2D filled rectangle in red and in the center a small rectangle is "taken out" so its fully transparent in the center.
Internet tells me to use a stencil buffer. Problem is, MSDN does not explain how to use it properly.
I think the problem lays somewhere else (for example my device not supporting it? I am using the DirectX simple sample just to learn about techniques) but here is my current code (I assure you I tried almost any combination of any of those values):
device->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
device->SetRenderState(D3DRS_STENCILENABLE, TRUE);
device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_INCRSAT);
device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, clearVertex, sizeof(RectangleVertex)); // small rectangle in center
device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_LESSEQUAL);
device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_ZERO);
device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, rectangleVertex, sizeof(RectangleVertex)); // big red rectangle
What am I doing wrong here? Thanks in advance for any help I can get.