我對Directx9中的簡單剪裁感興趣。 在最上面的圖片,你看到我得到。 我想在不改變座標和/或視口的情況下獲取底部圖片上的內容。 意思是說,我會繪製整個圓圈,但DirectX9會將其剪下。在DirectX中簡單剪裁9
剪輯矩形會在WINDOW座標中給出,所以它不會受到當前狀態轉換的影響。 此外,它應該影響從現在開始到窗口的所有內容,包括多邊形,精靈,紋理,文本等。
somone可以建議如何做到這一點?
我對Directx9中的簡單剪裁感興趣。 在最上面的圖片,你看到我得到。 我想在不改變座標和/或視口的情況下獲取底部圖片上的內容。 意思是說,我會繪製整個圓圈,但DirectX9會將其剪下。在DirectX中簡單剪裁9
剪輯矩形會在WINDOW座標中給出,所以它不會受到當前狀態轉換的影響。 此外,它應該影響從現在開始到窗口的所有內容,包括多邊形,精靈,紋理,文本等。
somone可以建議如何做到這一點?
你正在描述一種內置於directx設備中的剪刀測試。
更具體地說,您只需設置在屏幕的矩形座標使用SetScissorRect
,然後通過調用
device->SetRenderState(D3DRS_SCISSORTESTENABLE , TRUE);
謝謝!我會嘗試。 –
我一個月前有同樣的問題,我試圖找到一個裁剪方法後,想出了一個解決辦法我自己,所以我不得不開發自己的...這應該工作:
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);
};
它需要一個表面和一個backbuffer ... – Deukalion
使剪刀測試這是否幫助:HTTP:// WWW .toymaker.info/Games/html/clipping.html? – Deukalion