void ID3DApplication::DoFlip(void) { if (!IsActive()) { return; } IApplication::DoFlip(); HRESULT hres; hres = m_pDevice->Present(NULL, NULL, NULL, NULL); if (FAILED(hres)) { hres = m_pDevice->TestCooperativeLevel(); if (FAILED(hres)) { // device is in lost state, and all non-managed // video memory resources are lost and need to // be re-loaded OnDeviceLost(); m_pDevice->Reset(&m_Present); SetDeviceDefaults(); if (FAILED(OnRestore())) { // game level application failed to // restore the video memory resources // nothing we can do about it... Close(); } } } }
void ID3DApplication::HandleWindowSizeChange(void) { if (IsWindowed() && IsActive() && m_pDevice) { // compare new and old size and reset the device // if necesasry if (m_Present.BackBufferWidth != (DWORD) GetWindowRect().right || m_Present.BackBufferHeight != (DWORD) GetWindowRect().bottom) { // window size has changed, get the new size m_Present.BackBufferWidth = GetWindowRect().right; m_Present.BackBufferHeight = GetWindowRect().bottom; OnDeviceLost(); // reset the 3d device m_pDevice->Reset(&m_Present); SetDeviceDefaults(); if (FAILED(OnRestore())) { Close(); } } } }
void WindowResized() { if (d3dmgr == NULL) { return; } IDirect3DSwapChain9 *sc; d3dmgr->GetSwapChain(0, &sc); D3DPRESENT_PARAMETERS d3dpp; sc->GetPresentParameters(&d3dpp); int ww = window_get_width(), wh = window_get_height(); d3dpp.BackBufferWidth = ww <= 0 ? 1 : ww; d3dpp.BackBufferHeight = wh <= 0 ? 1 : wh; sc->Release(); OnDeviceLost(); d3dmgr->Reset(&d3dpp); OnDeviceReset(); // clear the window color, viewport does not need set because backbuffer was just recreated enigma_user::draw_clear(enigma_user::window_get_color()); }
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { HANDLE_MSG(hwnd, WM_CREATE, OnCreate); HANDLE_MSG(hwnd, WM_CLOSE, OnClose); HANDLE_MSG(hwnd, WM_PAINT, OnPaint); HANDLE_MSG(hwnd, WM_SIZE, OnSize); HANDLE_MSG(hwnd, WM_COMMAND, OnCommand); case WM_DEVICECHANGE: OnDeviceLost(hwnd, (PDEV_BROADCAST_HDR)lParam); return TRUE; case WM_ERASEBKGND: return 1; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } }