2

Directx9 での単純な rect クリッピングに興味があります。 ここに画像の説明を入力 上の写真で、私が得たものを見ることができます。座標やビューポートを変更せずに、下の画像にあるものを取得したい。つまり、円全体を描画しますが、Directx9 はそれを切り取るだけです。

現在の状態変換の影響を受けないように、clip rect は WINDOW 座標で指定することが望ましいでしょう。さらに、ポリゴン、スプライト、テクスチャ、テキストなどを含む、これからウィンドウに移動するすべてに影響するはずです。

誰かがこれを行う方法を提案できますか?

4

2 に答える 2

3

directx デバイスに組み込まれているシザー テストについて説明しています。

シザーテストを参照してください

より具体的には、SetScissorRectを使用して画面座標で長方形を設定するだけです

そして、呼び出してシザーテストを有効にします

device->SetRenderState( D3DRS_SCISSORTESTENABLE , TRUE );
于 2013-02-14T21:56:36.487 に答える
0

1か月前に同じ質問があり、クリッピング方法を見つけようとした後、自分で解決策を思いついたので、独自の方法を開発する必要がありました...これはうまくいくはずです:

void Clip(LPDIRECT3DDEVICE9 device, LPDIRECT3DSURFACE9 surface, LPDIRECT3DSURFACE9 backbuffer, int x, int y, int width, int height, int destX, int destY, int destWidth, int destHeight)
{
    RECT source;

    if (x >= destX && (x+width) <= (destX+destWidth))
    {
        source.left = 0;
        source.right = width;
    }
    else if ( (x >= destX && x <= (destX+destWidth)) && ((x+width) > (destX+destWidth)))
    {
        source.left = 0;
        source.right = width - ((x+width) - (destX+destWidth));
        source.right = abs(source.right);
    }
    else if (x < destX && (x+width) < (destX+destWidth))
    {
        source.left = abs(x);
        source.right = width;
    }
    else if ( (x < destX) && ((x+width) > (destX+destWidth)))
    {
        source.left = abs(x);
        source.right = source.left + (destWidth);
    }
    else
    {   
        return;
    }


    if (y >= destY && (y+height) <= (destY+destHeight))
    {
        source.top = 0;
        source.bottom = height;
    }
    else if ( (y >= destY && y <= (destY+destHeight)) && ((y+height) > (destY+destHeight)) )
    {
        source.top = 0;
        source.bottom = height - ((y+height) - (destY+destHeight));
        source.bottom = abs(source.bottom);
    }
    else if (y < destY && (y+height) > destY && (y+height) <= (destY+destHeight))
    {
        source.top = abs(y);
        source.bottom = height;
    }
    else if ( (y < destY) && ((y+height) > (destY+destHeight)))
    {
        source.top = abs(y);    
        source.bottom = source.top + (destHeight);
    }
    else
    {
        return;
    }


    RECT destination;

    if (x >= destX && (x+width) <= (destX+destWidth))
    {
        destination.left = x;
        destination.right = x + width;
    }
    else if ( (x >= destX && x <= (destX+destWidth)) && ((x+width) > (destX+destWidth)))
    {
        destination.left = x;
        destination.right = (destX+destWidth);
    }
    else if ( (x < destX) && ((x+width) < (destX+destWidth)) && ((x+width) >= x))
    {
        destination.left = destX;
        destination.right = width - abs(x);
    }
    else if ( (x < destX) && ((x+width) > (destX+destWidth)))
    {
        destination.left = destX;
        destination.right = (destX+destWidth);
    }
    else
    {   
        return;
    }

    if (y >= destY && (y+height) <= (destY+destHeight))
    {
        destination.top = y;
        destination.bottom = y + height;
    }
    else if ( (y >= destY && y <= (destY+destHeight)) && (y+height) > (destY+destHeight))
    {
        destination.top = y;
        destination.bottom = (destY+destHeight);
    }
    else if (y < destY && (y+height) > destY && (y+height) <= (destY+destHeight))
    {
        destination.top = destY;
        destination.bottom = height - abs(y);
    }
    else if ( (y < destY) && ((y+height) > (destY+destHeight)))
    {
        destination.top = destY;
        destination.bottom = (destY+destHeight);
    }
    else
    {
        return;
    }

    device->StretchRect(surface, &source, backbuffer, &destination, D3DTEXF_NONE);      

    DeleteObject(&source);
    DeleteObject(&destination);
};
于 2013-02-02T10:48:38.957 に答える