2

我对 Directx9 中的简单矩形剪辑感兴趣。 在此处输入图像描述 在上面的图片中,您可以看到我得到的。我想在不更改坐标和/或视口的情况下获得底部图片上的内容。意思是,我会画出整个圆圈,但 Directx9 只会剪辑它。

最好在窗口坐标中给出剪辑矩形,这样它就不会受到当前状态转换的影响。此外,它应该会影响从现在开始到窗口的所有内容,包括多边形、精灵、纹理、文本等。

有人可以建议如何做到这一点吗?

4

2 回答 2

3

您正在描述一种剪式测试,它内置于 directx 设备中。

剪刀测试

更具体地说,您只需使用SetScissorRect在屏幕坐标中设置矩形

然后通过调用启用剪刀测试

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

一个月前我有同样的问题,我在尝试找到一种剪裁方法后自己想出了一个解决方案,所以我不得不开发自己的......这应该可以工作:

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 回答