Sign in to follow this  

PLEASE give me clipping code!!

This topic is 4777 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I cannot figure clipping out, I've searched everywhere on the internet and when I try to piece it together, it doesn't work. If you know how to do clipping with direct draw 7 (my direct draw object is lpdirectdraw7, NOT lpdirectdraw) please give me the code for clipping. I already have all the animation working, it's just the clipping code that I need.

Share this post


Link to post
Share on other sites
This is also your 5th post with the same question. Perhaps, as davidx9 suggested, you could be more specific in your question. Outline what you are trying to accomplish, what you have tried, exactly how what you tried failed, show the code your are having problems with, etc.

Share this post


Link to post
Share on other sites
I want to clip partly off screen sprites on my
640*480 back/front surfaces.

Basically, I have my front and back surfaces set up,
my direct draw objects, etc..

here's what I tried first:


LPRGNDATA rd;
RECT cliprect = {0,0,639,479};
ddrval = lpdd7->CreateClipper(0, &clipper, NULL);
rd = (LPRGNDATA) malloc (sizeof(RGNDATAHEADER) + sizeof(RECT));
memcpy(rd->Buffer, &cliprect, sizeof(RECT));

rd->rdh.dwSize = sizeof(RGNDATAHEADER);
rd->rdh.iType = RDH_RECTANGLES;
rd->rdh.nCount = 1;
rd->rdh.nRgnSize = sizeof(RECT);
rd->rdh.rcBound.left = 0;
rd->rdh.rcBound.right = 639;
rd->rdh.rcBound.top = 0;
rd->rdh.rcBound.bottom = 479;

ddrval = clipper->etClipList(rd,0);
if (ddrval != DD_OK)
{
exit(1);
}
ddrval = lpDDSBack->SetClipper(clipper);
if (ddrval != DD_OK)
{
exit(2);
}




I also tried this:


ddrval = lpdd7->CreateClipper(0, &clipper, NULL);
if (ddrval != DD_OK)

{
exit(1);
}
clipper->SetHWnd(0, hWnd);
// yes I do have a global hWnd window handle that is
// instantiated correctly
lpDDSPrimary->SetClipper(clipper);
clipper->Release();



two different code sources I found on the internet,
I don't know which method is closer to what I need
to do. I'm really lost, basically.

Share this post


Link to post
Share on other sites
Quote:
Original post by furthermore
Do you maybe mean collision detection?


Heh, he actually might want to induce clipping somehow. Maybe his collision detection system works too well and he'd the game to have a few bugs worthy of a patch/expansion. Silliness.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dave Hunt
There is an article right here on GemDev.net that shows how to set this up. Apparently, you didn't "search everywhere."


are the priniples used in that outdated tut with DirectDraw the same as what you would use with D3D ?

Share this post


Link to post
Share on other sites
Ya, i had bunked code too. try this site
http://www.falloutsoftware.com/tutorials/dd/dd6.htm

taken from that site, but slightly changed, seems to work fine tho...

bool CreateClipper(LPDIRECTDRAWSURFACE7 surface, LPDIRECTDRAW7 lpdd7, LPDIRECTDRAWCLIPPER clipper, int x, int y, int width, int height)
{
LPRGNDATA rd;
RECT cliprect = {x, y, width, height};
HRESULT hr;

if(FAILED(lpdd7->CreateClipper(0, &clipper, NULL)))
{
return(false);
}

rd = (LPRGNDATA)malloc(sizeof(RGNDATAHEADER) + sizeof(RECT));
memcpy(rd->Buffer, &cliprect, sizeof(RECT));

rd->rdh.dwSize = sizeof(RGNDATAHEADER);
rd->rdh.iType = RDH_RECTANGLES;
rd->rdh.nCount = 1;
rd->rdh.nRgnSize = sizeof(RECT);
rd->rdh.rcBound.left = x;
rd->rdh.rcBound.right = x+width;
rd->rdh.rcBound.top = y;
rd->rdh.rcBound.bottom = y+height;

hr = clipper->SetClipList(rd, 0);
if(hr != DD_OK)
{
return(false);
}

hr = surface->SetClipper(clipper);

if(hr != DD_OK)
{
return(false);
}

free(rd);

return(true);
}


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Uhhh, why are you calling Clipper->Release()? Isn't that a dumb thing to do if you ARE STILL TRYING TO USE IT?

Disclaimer: I'm a jerk, and it's been years since I've written straight DDraw (not since 5).

Share this post


Link to post
Share on other sites
Quote:
Original post by netflow
Quote:
Original post by Dave Hunt
There is an article right here on GemDev.net that shows how to set this up. Apparently, you didn't "search everywhere."


are the priniples used in that outdated tut with DirectDraw the same as what you would use with D3D ?


No, but jimiwa isn't using D3D. He's using DirectDraw.

Share this post


Link to post
Share on other sites
Jimiwa: I have closed your other four posts all asking the same thing. Do NOT repost this question again. One thread is sufficient.

Share this post


Link to post
Share on other sites
Okay, I'm still not getting it. It runs now,
but doesn't clip the bitmaps. If they're partly
offscreen they don't show up at all.


bool cSurface::Draw(LPDIRECTDRAWSURFACE7 lpDest, int iDestX, int iDestY,
int iSrcX, int iSrcY, int nWidth, int nHeight,
LPDIRECTDRAW7 lpDD7)
{
RECT rcRect;
rcRect.left = 0;
rcRect.top = 0;
rcRect.right = nWidth;
rcRect.bottom = nHeight;
HRESULT hRet;

if(nWidth == 0)
nWidth = m_Width;

if(nHeight == 0)
nHeight = m_Height;

ClipSurface(lpDD7, iDestX,iDestY,nWidth,nHeight, rcRect);
while(1)
{
if((int)m_ColorKey < 0)
{
hRet = lpDest->BltFast(iDestX, iDestY, m_pSurface,
&rcRect, DDBLTFAST_NOCOLORKEY);
}
else
{
hRet = lpDest->BltFast(iDestX, iDestY, m_pSurface,
&rcRect, DDBLTFAST_SRCCOLORKEY);
}

if(hRet == DD_OK)
break;

else
{
if(hRet != DDERR_WASSTILLDRAWING)
return FALSE;
}
}

return TRUE;
}

void cSurface::ClipSurface(LPDIRECTDRAW7 lpdd7,
int x, int y, int width, int height,
RECT cliprect)
{
// RECT cliprect = {x,y,x+width,y+height};
HRESULT ddrval;
LPRGNDATA rd;
ddrval = lpdd7->CreateClipper(0,&clipper, NULL);
rd = (LPRGNDATA)malloc(sizeof(RGNDATAHEADER) + sizeof(RECT));
memcpy(rd->Buffer, &cliprect, sizeof(RECT));
rd->rdh.dwSize = sizeof(RGNDATAHEADER);
rd->rdh.iType = RDH_RECTANGLES;
rd->rdh.nCount = 1;
rd->rdh.nRgnSize = sizeof(RECT);
rd->rdh.rcBound.left = x;
rd->rdh.rcBound.right = x+width;
rd->rdh.rcBound.top = y;
rd->rdh.rcBound.bottom = y + height;
ddrval = clipper->SetClipList(rd,0);
ddrval = m_pSurface->SetClipper(clipper);
free(rd);
}

Share this post


Link to post
Share on other sites
As the tutorial from which you took that code explains, the clipper should created at initialization and should be attached to the back buffer. You are creating a new clipper each frame and attaching it to your source surface.

I would strongly suggest you read through the tutorials very carefully and make sure you understand them before trying to use the code.

Share this post


Link to post
Share on other sites
OK, I see a few problems here

1)Firstly, you can't use BltFast with a clipper. You MUST use Blt()
2)Why are you asigning ClipSurface everytime you draw? You only need to do it once, at the initialization, and pass it the screen width/height
like so...

//init ddsd/Dx, etc here
...
//create this as your last step
///this is for a 800x600 screen
if(!CreateClipper(MYmainSurface, lpdd7, myclipper, 0,0, 800, 600))
{
//error out
}


3)Also, your not passing a Clipper object(LPDIRECTDRAWCLIPPER) to your CreateClipper thingy. Why are you passing a RECT?
4)Are you trying to set up a clipper list? So, you can clip many different areas?

Cheers

Sigma

Share this post


Link to post
Share on other sites

This topic is 4777 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this