Clipping – (overhead)
If
the source does not fit on the destination surface, a Blit
operation will trash memory locations outside the destination unless you clip.
To
set up the clipper:
· create a DD clipper object
· create a clipper list
· send list to the clipper w/ SetClipList()
· attach clipper to the window
or surface w/ SetClipper()
CreateClipper (0,
<addr of ptr to
interface>, NULL);
The
interface ptr will be set after a successful call to CreateClipper.
Example:
//
create a clipper
LPDIRECTDRAWCLIPPER
lpddclipper = NULL; // clipper ptr
CreateClipper (0, &lpddclipper,
NULL);
Clipper Lists – a list of RECTs indicating valid regions to Blit
to.
typedef
struct _RGNDATA
{ RGNDATAHEADER rdh; // header info
char
Buffer[1]; // var
len list of RECTs
} RGNDATA;
To
create one:
· new memory to create a data struct to hold your list
o
RGNDATA HEADER
o
RECT 1 // first entry in
buffer
o
RECT 2 …
· Fill in header date
Typedef struct _RGNDATAHEADER
{ DWORD dwSize; // header size sizeof(RGNDATAHEADER)
DWORD iType; // region type (Rectangle)
DWORD nCount; // # of regions
DWORD nRgnSize;// buffer size – sizeof(RECT) * nCount
DWORD rcBound; // bounding RECT
for all regions
} RGNDATAHEADER
· Cast it to a RGNDATA object
· Send it to the clipper with
lpddclipper->SetClipList(<ptr to list>, 0);
· Attach it to the surface
(usually back buffer) with
lpddsurface->SetClipper(<<ptr to clipper>);