반응형
void CaptureScreen(LPDIRECT3DDEVICE9 pDevice, TCHAR szFileName) { if (!pDevice || !szFileName) return; DWORD tickStart = GetTickCount(); // There is 2 Methods // 1. Capture Front Buffer // 2. Capture Back Buffer (Faster) bool isBackBuffer = true; RECT rectWindow = {0}; RECT rectDesktop = {0}; GetClientRect(g_hMainWnd, &rectWindow); GetClientRect(GetDesktopWindow(), &rectDesktop); IDirect3DSurface9* pSurface = NULL; HRESULT hResult = S_OK; if (isBackBuffer) { hResult = pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurface); } else { /* For windowed mode, the size of the destination surface should be the size of the desktop. For full-screen mode, the size of the destination surface should be the screen size. */ bool isFullScreen = IsFullScreenMode(); int nWidth = isFullScreen ? rectWindow.right - rectWindow.left : rectDesktop.right - rectDesktop.left; int nHeight = isFullScreen ? rectWindow.bottom - rectWindow.top : rectDesktop.bottom - rectDesktop.top; hResult = pDevice->CreateOffscreenPlainSurface(nWidth, nHeight, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pSurface, NULL); hResult = pDevice->GetFrontBufferData(0, pSurface); } if (pSurface) { hResult = D3DXSaveSurfaceToFile(szFileName, D3DXIFF_JPG, pSurface, NULL, &rectWindow); pSurface->Release(); } tickDiff = GetTickCount() - tickStart; }
Back Buffer를 Capture하는 것이 더 빠르다.
- Back Buffer : 500~600ms
- Front Buffer : 1300~1400ms
Test 환경
- CPU : Core2 Duo E650 @ 2.33GHz
- RAM : 1024MB
- VGA : NVIDIA GeForce 8500 GT (512MB)
- Window 크기 : 1024 * 768
반응형
'Game Dev > Article' 카테고리의 다른 글
Memory Mapped File (0) | 2008.07.22 |
---|---|
Kill Process (0) | 2008.07.18 |
Send Stream to Notepad (0) | 2008.06.09 |
Accurately Profiling Direct3D API Calls (Direct3D 9) (0) | 2008.06.09 |