DirectDraw Clipper

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cbbibleboy
    New Member
    • Apr 2007
    • 29

    DirectDraw Clipper

    Howdy!
    I'm having a bit of trouble with my DirectDraw clipper. The code compiles fine and runs without a hitch; however, it doesn't work. That is, there is no clipping! I get the exact same behavior as when I have no clipper used. It's all very mysterious as I've compared my code with dozens of others' that work, yet I can't find any differences in mine. I've tried to reduce my relevant code to as little as possible. Here is the function that initializes all my DirectX Stuff and returns the hWnd (minus some error-catching calls to simplify things):

    Code:
    int InitDirectDraw(HWND hWnd)
    {
    	DDSURFACEDESC2	ddsd;
    	DDSCAPS2		ddscaps;
    	HRESULT			hRet;
    
    	// Create the main DirectDraw object.
    	hRet = DirectDrawCreateEx(NULL, (VOID**)&lpDD, IID_IDirectDraw7, NULL);
    	if( hRet != DD_OK ) return -1;
    
    	// Get exclusive mode.
    	hRet = lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | DDSCL_ALLOWREBOOT);
    	if( hRet != DD_OK ) return -2;
    
    	// Set the video mode to 640x480x16.
    	hRet = lpDD->SetDisplayMode(640, 480, 16, 0, 0);
    	if( hRet != DD_OK ) return -3;
    
    	// Prepare to create the primary surface by initializing
    	// the fields of a DDSURFACEDESC2 structure.
    	ZeroMemory(&ddsd, sizeof(ddsd));
    	ddsd.dwSize = sizeof(ddsd);
    	ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
    	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
    	ddsd.dwBackBufferCount = 1;
    
    	// Create the primary surface.
    	hRet = lpDD->CreateSurface(&ddsd, &lpDDSFront, NULL);
    	if( hRet != DD_OK ) return -1;
    
    	// Get a pointer to the back buffer.
    	ZeroMemory(&ddscaps, sizeof(ddscaps));
    	ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
    	hRet = lpDDSFront->GetAttachedSurface(&ddscaps, &lpDDSBack);
    	if( hRet != DD_OK ) return -1;
    
    	// Clipper Initialization
    
    	// Create the clipper using the DirectDraw object
    	lpDD->CreateClipper(0, &lpDDClipper, NULL);
    
    	// Assign your window's HWND to the clipper
    	lpDDClipper->SetHWnd(0, hWnd);
    	
    	// Attach the clipper to the primary surface
    	lpDDSFront->SetClipper(lpDDClipper);
    
    	return 0;
    }
    And here is how it's called:

    Code:
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow)
    {
    	hInst = hInstance;
    	hWnd = InitWindow(hInst, nCmdShow); 
    
    	if(!hWnd) return -1;
    
    	if(InitDirectDraw(hWnd) < 0)
    	{
    		CleanUp();
    		MessageBox(hWnd, "Could not start DirectX engine in your computer. Make sure you have at least version 7 of DirectX installed.", "Error", MB_OK | MB_ICONEXCLAMATION);
    		return 0;
    	}
    	
    	. . .
    
    	CleanUp();
    
    	return 0;
    }
  • cbbibleboy
    New Member
    • Apr 2007
    • 29

    #2
    I'm afraid my post may not have been noticed so, per forum rules, I am posting this message. I'm working on a large project, but will unfortunately be completely unable to progress until this issue has been solved.

    Thanks in advance! :)

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      This code:
      Code:
      lpDD->CreateClipper(0, &lpDDClipper, NULL);
      has these return values:

      DDERR_INVALIDOB JECT The object is invalid.
      DDERR_INVALIDPA RAMS One or more of the input parameters is invalid.
      DDERR_OUTOFMEMO RY DirectDraw does not have enough memory to perform the operation.
      DDERR_NOCOOPERA TIVELEVELSET

      but I don't see that you check for them.

      Code:
      lpDDClipper->SetHWnd(0, hWnd);
      also has return values that are not checked for:

      DDERR_INVALIDCL IPLIST
      DDERR_INVALIDOB JECT
      DDERR_INVALIDPA RAMS
      DDERR_OUTOFMEMO RY


      Are you sure your calls are working as expected?

      Comment

      • cbbibleboy
        New Member
        • Apr 2007
        • 29

        #4
        Yeah, for the sake of simplicity I left out the error-checking, but it's there. There are no errors. It's just not doing anything...

        Comment

        Working...