I'm trying to render a surface with a method that takes a Surface and X, Y position to render at. The problem is that when the surface is outside the screen by one small pixel, it doesn't render at all.
Why is that? I'm trying to search for DirectX clipping but can't find anything at all.
void Draw(LPDIRECT3DSURFACE9 src, int x, int y)
{
D3DSURFACE_DESC desc;
src->GetDesc(&desc);
D3DVIEWPORT9 viewport;
Device->GetViewport(&viewport);
int vX = viewport.X;
int vY = viewport.Y;
int vWidth = viewport.X + viewport.Width;
int vHeight = viewport.Y + viewport.Height;
RECT source;
source.left = max(x, vX);
source.right = min(source.left + desc.Width, vWidth);
source.top = max(y, vY);
source.bottom = min(source.top + desc.Height, vHeight);
RECT destination;
destination.left = max(x, vX);
destination.right = min(destination.left + desc.Width + x, vWidth);
destination.top = max(y, vY);
destination.bottom = min(destination.top + desc.Height + y, vHeight);
Device->StretchRect(src, &source, BackBuffer, &destination, D3DTEXF_POINT);
};
...and X = 100, Y = 100 doesn't work but -100 does but it doesn't stretch it right.
Example image of desired effect:
I've also been trying to set the *pSourceRect and *pDestRect to something that clips the surface but without any luck.
I'm using DirectX9.