PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

MFC/Offscreen surfaces

I'm having an issue in porting my MFC/DirectX application to GapiDraw/MFC.

I'm porting an MFC extension DLL which has two primary types of clients - DC clients and DirectX clients. Internally the DLL caches bitmaps as DirectX offscreen surfaces which are BLTed to a back buffer surface which is also owned by the DLL. How do I create offscreen surfaces w/GapiDraw? My old code for doing this follows. When using GapiDraw it seems like I have to invoke OpenDisplay. I'm following the documentation and passing AfxGetMainWnd()->GetSafeHwnd(). Notice in the code below there is no need to reference a HWND.

// create the main DirectDraw object
TRYRET_DD (DirectDrawCreateEx( NULL, (LPVOID *)&lpDD1, IID_IDirectDraw7, NULL ), error);

// Set to normal mode
TRYRET_DD (lpDD1->SetCooperativeLevel( NULL, DDSCL_NORMAL ), error);

// Get DirectDraw7 interface
TRYRET_DD (lpDD1->QueryInterface(IID_IDirectDraw7, (LPVOID *)&m_lpDD), error);

lpDD1->Release();

DDSURFACEDESC2 ddsd;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof( ddsd );
ddsd.dwWidth = hSize;
ddsd.dwHeight = vSize;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;


TRYRET_DD (m_lpDD->CreateSurface( &ddsd, &m_FrontBuffer , NULL ), error);

TRYRET_DD (m_lpDD->CreateSurface( &ddsd, &m_BackBuffer, NULL ), error);


Thanks,
Bill
Hi Bill,

Did you solve this issue? All surfaces in GapiDraw (except the one and single instance of CGapiDisplay) are offscreen surfaces. The reason you need to call OpenDisplay first is because all surfaces (offscreen as well) are stored in a format compatible with the display.

There is currently no way of creating offscreen surfaces without first calling OpenDisplay.

Best regards,
Johan