Search code examples
c++windowsdirectx-9

Simple Clipping in DirectX 9


I am interested in simple rect clipping in Directx9. enter image description here On the top picture you see what I get. I want to get what is on the bottom picture without changing the coordinates and/or viewport. Meaning, I will draw the entire circle but Directx9 will just clip it.

It would be preferable that clip rect will be given in WINDOW coordinates, so it will not be affected by current state transformations. In additions, it should affect everything going from now on to window, including polygons, sprites, textures, text etc.

Can somone suggest how to do this?


Solution

  • You're describing a scissor test, which is built into the directx device.

    See Scissor Test

    More specifically, you just set the rectangle in screen coordinates using SetScissorRect

    And then enable the scissor test by calling

    device->SetRenderState( D3DRS_SCISSORTESTENABLE , TRUE );