Archived

This topic is now archived and is closed to further replies.

Directx Question:

This topic is 6355 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

Hey, Well I have a clipper. Ok now lets say I have a resolution set to 640 x 480, and then I blt a background of 640 x 480, well that works, now I try to blt a sprite, using the Blt funtion not the Bltfast, the sprite is 100 x 100 big and I blt it at (620,410), That means that some of the sprite is off the screen, but the clipper should clip it like this right:
                        

      -------------------------
      |                       |
      |                       |
      |                       |
      |  primary suface       |
      |                       |
      |                -----------
      |                |      |  |
      |                |      |  |
      -----------------|-------  | <--- Sprite
                       |         | <---- This Should be clipped.
                       -----------

The sprite should be clipped by ther clipper where it is off the
 screen right? Well thats what I thought but when I blt using
 the Blt() funtion I get an DDERR_INVALIDRECT error. If I blt the
 sprite where its all on the screen im fine, but I want to
 create a tile map and if I dont have a clipper that will almost
 be impossible. 

[/source]

Here is the source code I use to create the clipper and attach
 it to the flipping chane or in other words the back surface.

[source]

        LPDIRECTDRAWCLIPPER   lpddclipper; // DirectObject Clipper

        LPRGNDATA           clipper; // Rect and info about the clipper object


        if(FAILED(lpDD->CreateClipper(0, &lpddclipper, NULL))) {
		MessageBox(hwnd, "no dude 1", "", MB_OK);
	}
	clipper = (LPRGNDATA)malloc(sizeof(RGNDATAHEADER)+1*sizeof(RECT));
	clipper->rdh.dwSize = sizeof(RGNDATAHEADER);
	clipper->rdh.iType = RDH_RECTANGLES;
	clipper->rdh.nCount = 1;
	clipper->rdh.nRgnSize = 1 * sizeof(RECT);	
	clipper->rdh.rcBound.top = 0;
	clipper->rdh.rcBound.left = 0;
	clipper->rdh.rcBound.right = 639;	
	clipper->rdh.rcBound.bottom = 479;	
	if(FAILED(lpddclipper->SetClipList(clipper, 0))) {	
		MessageBox(hwnd, "no dude 2", "", MB_OK);
	}
	if(FAILED(lpDDSPrimary->SetClipper(lpddclipper))) {	
		MessageBox(hwnd, "no dude 3", "", MB_OK);
	}
	free(clipper);  

[/source]

Now am I creating the clipper incorrect or attaching it to the 

surface wrong? I use the Blt not the Bltfast, so I know thats 

not the problem, here is my blting code so you can see:


[source] 

        DDSURFACEDESC2       ddsd;
	DDSCAPS2             ddscaps;
	DDBLTFX             ddbltfx;
	HRESULT             ddrval;
	RECT                srcRect;
	RECT                destRect;
	char                buffer[256];

        srcRect.top = 20;
	srcRect.left = 20;
	srcRect.right = 70;
	srcRect.bottom = 70;

	destRect.top = ypos;
	destRect.left = xpos;
	destRect.right = xpos + 50 - 1;
	destRect.bottom = ypos + 50 - 1;

	ZeroMemory( &ddbltfx, sizeof( ddbltfx ) );
        ddbltfx.dwSize = sizeof( ddbltfx );

	ddrval = lpDDSBack->Blt(NULL, lpDDSOffTwo, NULL, DDBLT_WAIT , NULL);
	

	ddrval = lpDDSBack->Blt(&destRect, lpDDSOffOne, &srcRect, DDBLT_WAIT | DDBLT_KEYSRC , NULL);

                        
Well if someone could tell me what im doing wrong I would like that, Thanks James, Later

Share this post


Link to post
Share on other sites
Does this also happen if it goes off of the primary surface on the upper left side or is it only the lower right side that causes the problem?

-> Briar LoDeran <-

Edited by - BriarLoDeran on July 17, 2000 12:23:07 PM

Share this post


Link to post
Share on other sites
You are creating your clipper the hard way.

This is the easy way:

    //Create the clipper for our window

if( FAILED( lpdd4->CreateClipper(0, &clipper, NULL)))
Error("Couldn''t create the clipper");

//Set the window the clipper shold be attached to

if( FAILED( clipper->SetHWnd(0, hwnd)))
Error("Couldn''t set the clipper to the window handle");

//Set the clipper to the primary surface

if( FAILED( lpddssecondary->SetClipper(clipper)))
Error("Couldn''t set the clipper to the primary surface");

Share this post


Link to post
Share on other sites
You could also adjust the SRC and DEST rectangles before blitting using Blt().

I don''t know which works faster; this probably depends on effectivity of the custom-clipper routine and the number of sprites to be clipped...

Greetings, CondorWitte.

Share this post


Link to post
Share on other sites