Hi, experts at Direct3D,
I am currently developing an application with Direct3D in order to capture my dual-monitor desktop (of course, used as an extended desktop). The following code works well, but I can just capture the main display and not the extended desktop (only one screen is captured twice)
How can I adapt this solution for dual screen capture?
First of all, I initialize Direct3D:
D3DDISPLAYMODE d3dDisplayMode; D3DPRESENT_PARAMETERS d3dPresentationParameters; //Presentation parameters (backbufferwidth, height...) if( (pSinfo->g_pD3D=Direct3DCreate9(D3D_SDK_VERSION)) == NULL ) return FALSE; if( pSinfo->g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3dDisplayMode) == D3DERR_INVALIDCALL ) return FALSE; ZeroMemory(&d3dPresentationParameters,sizeof(D3DPRESENT_PARAMETERS)); d3dPresentationParameters.Windowed = TRUE; d3dPresentationParameters.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; d3dPresentationParameters.BackBufferFormat = d3dDisplayMode.Format; d3dPresentationParameters.BackBufferHeight = gScreenRect.bottom = d3dDisplayMode.Height; d3dPresentationParameters.BackBufferWidth = gScreenRect.right = d3dDisplayMode.Width; d3dPresentationParameters.MultiSampleType = D3DMULTISAMPLE_NONE; d3dPresentationParameters.SwapEffect= D3DSWAPEFFECT_DISCARD; d3dPresentationParameters.hDeviceWindow = hWnd; d3dPresentationParameters.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; d3dPresentationParameters.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; pSinfo->uiWidth = d3dDisplayMode.Width; pSinfo->uiHeight = d3dDisplayMode.Height; if( pSinfo->g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_REF,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING ,&d3dPresentationParameters,&pSinfo->g_pd3dDevice) != D3D_OK ) return FALSE;
And then, a loop that takes continuous screenshots and stores the image data in pData:
while(1) { pSinfo->g_pd3dDevice->GetRenderTarget(0, &pSinfo->pRenderSurface); pSinfo->g_pd3dDevice->CreateOffscreenPlainSurface(pSinfo->uiWidth, pSinfo->uiHeight, pSinfo->d3dFormat, D3DPOOL_SYSTEMMEM, &pSinfo->pRenderSurface, NULL); pSinfo->g_pd3dDevice->GetFrontBufferData(0, pSinfo->pRenderSurface); //D3DXSaveSurfaceToFile("Desktop.bmp", D3DXIFF_BMP, pSinfo->pRenderSurface,NULL, NULL); //Test ZeroMemory(&pSinfo->lockedRect, sizeof(D3DLOCKED_RECT)); pSinfo->pRenderSurface->LockRect(&pSinfo->lockedRect,NULL, D3DLOCK_READONLY); memcpy((BYTE*)pSinfo->pData, (BYTE*)pSinfo->lockedRect.pBits, (pSinfo->uiWidth) * pSinfo->uiHeight * pSinfo->uiBitsPerPixels/8); pSinfo->pRenderSurface->UnlockRect(); //InvalidateRect(((CMainFrame*)(pApp->m_pMainWnd))->m_hWnd,NULL,false); pSinfo->pRenderSurface->Release(); }
For clarity about the problem, I have a solution:
I have two monitors with my extended Windows desktop. when capturing the screen, I have two screenshots with the main screen, and what I want is one screenshot of the main screen and the other with an extended screen.
I think I need to set a parameter somewhere indicating that the extended desktop starts with Point.x = 1920 (for a 1080p screen), but I just don't know how to do this.
Thank you so much for your help!
Dylan
