HRESULT APPLICATION::Cleanup() { try { m_pFont->Release(); m_pLine->Release(); m_pDevice->Release(); debug.Print("Application terminated"); } catch(...){} return S_OK; }
void InitDX9App::drawScene() { HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0f, 0)); RECT formatRect; GetClientRect(mhMainWnd, &formatRect); HR(gd3dDevice->BeginScene()); mFont->DrawText(0, L"Hello Direct3D 9", -1, &formatRect, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256)); D3DXVECTOR2 line[] = { D3DXVECTOR2(0,0), D3DXVECTOR2(100.0f, 100.0f), D3DXVECTOR2(100.0f, 200.0f), }; mLine->Begin(); mLine->Draw(line, 3, D3DCOLOR_XRGB(255,0,0)); mLine->End(); HR(gd3dDevice->EndScene()); HR(gd3dDevice->Present(0, 0, 0, 0)); }
HRESULT APPLICATION::Render() { //Setup the viewport D3DVIEWPORT9 v, v2; v.Width = 800; v.Height = 600; v.X = 0; v.Y = 0; v.MaxZ = 1.0f; v.MinZ = 0.0f; m_pDevice->SetViewport(&v); v2 = v; // Clear the viewport m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff4444ff, 1.0f, 0L ); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { //Render big city m_city.Render(&m_camera); RECT r[] = {{10, 10, 0, 0}, {10, 30, 0, 0}, {10, 50, 0, 0}}; m_pFont->DrawText(NULL, "Mouse Wheel: Change Camera Radius", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "Arrows: Change Camera Angle", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); //Render city overview, set viewport v.X = 550; v.Y = 20; v.Width = 230; v.Height = 230; m_pDevice->SetViewport(&v); m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L ); //Setup camera view to orthogonal view looking down on city D3DXMATRIX viewTop, projectionTop; D3DXMatrixLookAtLH(&viewTop, &(m_city.GetCenter() + D3DXVECTOR3(0.0f, 100.0f, 0.0f)), &m_city.GetCenter(), &D3DXVECTOR3(0,0,1)); D3DXMatrixOrthoLH(&projectionTop, m_city.m_size.x * TILE_SIZE, m_city.m_size.y * TILE_SIZE, 0.1f, 1000.0f); m_pDevice->SetTransform(D3DTS_VIEW, &viewTop); m_pDevice->SetTransform(D3DTS_PROJECTION, &projectionTop); //Draw city blocks that are in view m_city.Render(NULL); //Restore viewport m_pDevice->SetViewport(&v2); //Draw line around smaller window D3DXVECTOR2 outline[] = {D3DXVECTOR2(550, 20), D3DXVECTOR2(779, 20), D3DXVECTOR2(779, 249), D3DXVECTOR2(550, 249), D3DXVECTOR2(550, 20)}; m_pLine->SetWidth(3.0f); m_pLine->Begin(); m_pLine->Draw(outline, 5, 0xff000000); m_pLine->End(); //Draw mouse m_mouse.Paint(); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }
void InitDX9App::onLostDevice() { HR(mFont->OnLostDevice()); HR(mLine->OnLostDevice()); }