PDA

Click to See Complete Forum and Search --> : DDClippers


Allanon
Feb 19th, 2001, 02:08 PM
How can I make a clipper, with cordinates

top- 4 pixels
left- 4 pixels
right - 674 pixels
bottom - 674 pixels

I can't use hWnd because I want to clip just part of the window. I don't know how to use
ddClip->SetClipList(*RGNDATA,0);
I don't know what to pass for RGNDATA

THANKS

drewski
Feb 19th, 2001, 11:24 PM
use getwindowrect to get where the window or picturebox is. then you you can move the top left corner down 4 pixels like so:

rprim.top = rprim.top + 4
rprim.left = rprim.left + 4

and then you could change the the bottom and right parts of the rect to what you wanted

rprim.bottom = 674
rprim.right= 674

i hope this is what you were looking for. i've never really used clippers in dx yet.

HarryW
Feb 20th, 2001, 03:30 PM
I'm assuming you're using C++ since you used C syntax.

RGNDATA is one of the annoying archaic old DX structures. It contains, among other things, a list of regions you want to clip to, and the number of regions you specify. You have to allocate memory for the array of regions yourself, and free the memory after you've created the cliplist.

Here are the structure defs:


typedef struct _RGNDATA
{
RGNDATAHEADER rdh; // header info
char buffer[1]; // the actual RECT list
} RGNDATA;


typedef struct _RGNDATAHEADER
{
DWORD dwSize; // size of this header in bytes
DWORD iType; // type of region data
DWORD nCount; // number of RECTs in buffer[]
DWORD nRgnSize; // size of buffer[]
RECT rcBound; // a bounding box around all RECTs
} RGNDATAHEADER;

drewski
Feb 20th, 2001, 07:35 PM
he sounds like he knows what he's doing ;)

Allanon
Feb 20th, 2001, 10:00 PM
Thanks HarryW, but how do I use that. I figured out what the syntax for RGNDATA was. I don't know how to make it so it clips a specific rect.

Thanks

HarryW
Feb 20th, 2001, 10:16 PM
Well you allocate enough memory for the number of RECTs you want to clip to in RGNDATA::buffer[], and fill your newly allocated array with the RECTs you want.

The RGNDATAHEADER describes the list of RECTs in buffer[]. You'll need to do something like this:

rdh.dwSize = sizeof(rdh);
rdh.iType = RDH_RECTANGLES;
rdh.nCount = NUMBER_OF_RECTS; // however many RECTs in your clip list
rdh.nRgnSize = sizeof(RECT)*rdh.nCount;

// also you need to set rdh.rcBound to a RECT
// which contains all your clipping regions. That's
// not too hard.


Then you make the calls you want to create the clipping list, and then free the memory in your RGNDATA structure.

Allanon
Feb 21st, 2001, 09:43 AM
One last question, what do I do for the buffer?

Thanks

HarryW
Feb 21st, 2001, 06:11 PM
Well buffer is just an array of RECTs at the end of your RGNDATA structure. Remember, the structure is contiguous in memory when you allocate memory for it, so all you have to do is allocate memory for the entire RGNDATA structure allowing for a RGNDATAHEADER (fixed size), and also enough space for however many RECTs you want to define in your cliplist. So, here's some code to do just that:
RGNDATA *pRegionData

if(!(pRegionData = (RGNDATA *)malloc(sizeof(RGNDATAHEADER) + NUMBER_OF_RECTS*sizeof(RECT))))
return(ERROR); // error checking - return an error code if you like

// now set up pRegionData->rdh, then fill buffer[] with however many RECTS you want

// DDraw call:
if(FAILED(lpddclipper->SetClipList(pRegionData, 0)))
{ if(!pRegionData) // shouldn't reasonably be NULL, but check anyway
free(pRegionData)
return(ERROR); // error checking - return an error code if you like
}

// DDraw call:
if(FAILED(lpdds->SetClipper(lpddclipper)))
{ if(!pRegionData) // shouldn't reasonably be NULL, but check anyway
free(pRegionData)
return(ERROR); // error checking - return an error code if you like
}

// now free your allocated memory
if(!pRegionData) // shouldn't reasonably be NULL, but check anyway
free(pRegionData);

// finished with clipper code and region data

Hope that helps, gimme a shout if you need any more :)

Allanon
Feb 22nd, 2001, 01:12 PM
Okay heres what I have, somethings not right, but I don't know what. I got rid of the error checking to make it easier to read

RECT ClipRect;
ClipRect.top = 4;
ClipRect.left =4;
ClipRect.right = 674;
ClipRect.bottom = 674;

lpDD->CreateClipper(0,&ddClipper,NULL);

RGNDATA *pRegionData;
pRegionData = (RGNDATA*)malloc(sizeof(RGNDATAHEADER) + sizeof(RECT));

RGNDATAHEADER rdh;
rdh.dwSize = sizeof(rdh);
rdh.rcBound = ClipRect;
rdh.iType =RDH_RECTANGLES;
rdh.nCount =1;
rdh.nRgnSize =sizeof(RECT);

pRegionData->rdh=rdh;

ddClipper->SetClipList(pRegionData,0);
ddsBuffer->SetClipper(ddClipper);

free(pRegionData);

Thanks a Lot!

HarryW
Feb 22nd, 2001, 07:49 PM
You need to put ClipRect in pRegionData->buffer[0].

pRegionData->buffer[0] = ClipRect;

HarryW
Feb 22nd, 2001, 07:56 PM
Oh, just realised you might get a type error since buffer is a char (I really don't know why... a RECT would be more sensible, but then it's an odd structure anyway). I also realised that Buffer should be capitalised (d'oh!).

This ought to work anyway:

memcpy(pRegionData->Buffer, &ClipRect, sizeof(RECT));

Allanon
Feb 22nd, 2001, 08:06 PM
Works Now, Thanks a Lot!! When I finish my game (couple of days) I'll post it so you can take a look at it

HarryW
Feb 22nd, 2001, 09:17 PM
Cool, no problem :)