//----------------------------------------------------------------------------- // Name: Render // Desc: //----------------------------------------------------------------------------- HRESULT CMyD3DApplication::Render() { HRESULT hr; if(FAILED(hr = m_pd3dDevice->BeginScene())) return hr; // Draw Environment FLOAT fAspectRatio = (FLOAT)m_d3dsdBackBuffer.Width / (FLOAT)m_d3dsdBackBuffer.Height; D3DXMatrixPerspectiveFovRH(&m_matProjection, D3DXToRadian(60.0f), fAspectRatio, 0.1f, 2000.0f); m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &m_matProjection); if(m_bDrawEnvironment) { D3DXMATRIX mat(m_matView); mat._41 = mat._42 = mat._43 = 0.0f; m_pd3dDevice->SetTransform(D3DTS_VIEW, &mat); m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); m_pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); m_Environment.Draw(); m_pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL); m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE); } else { m_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0); } m_pd3dDevice->SetTransform(D3DTS_VIEW, &m_matView); // Draw water if(m_bDrawWater) { // Setup matrices if(m_pEffect->IsParameterUsed("mENV")) { D3DXMATRIX matP(m_matPosition); matP._41 = matP._42 = matP._43 = 0.0f; D3DXMATRIX mat; D3DXMatrixScaling(&mat, 1.0f, 1.0f, -1.0f); D3DXMatrixMultiply(&mat, &matP, &mat); // matCube m_pEffect->SetMatrix("mENV", &mat); } // Draw water UINT uPasses; m_pEffect->Begin(&uPasses, 0); for(UINT uPass = 0; uPass < uPasses; uPass++) { m_pEffect->Pass(uPass); m_Water.DrawSurface(); } m_pEffect->End(); } // Show info m_pFont->DrawText( 2, 0, D3DCOLOR_ARGB(255,255,255,0), m_strFrameStats ); m_pFont->DrawText( 2, 20, D3DCOLOR_ARGB(255,255,255,0), m_strDeviceStats ); TCHAR szText[100]; wsprintf( szText, _T("Using Technique %d"), m_iTechnique ); m_pFontSmall->DrawText( 2, 40, D3DCOLOR_ARGB(255,255,100,100), szText ); if( m_bShowHelp ) { m_pFontSmall->DrawText( 2, 60, D3DCOLOR_ARGB(255,100,100,200), _T("Keyboard controls:") ); m_pFontSmall->DrawText( 20, 80, D3DCOLOR_ARGB(255,100,100,200), _T("Add Drop\n") _T("Next Technique\n") _T("Next Tech. (no validate)\n") _T("Prev Technique\n") _T("Prev Tech. (no validate)\n") _T("Move\nTurn\nPitch\nSlide\n") _T("Help\nChange device\nExit") ); m_pFontSmall->DrawText( 210, 80, D3DCOLOR_ARGB(255,100,100,200), _T("D\n") _T("PageDn\nShift-PageDn\n") _T("PageUp\nShift-PageUp\n") _T("W,S\nE,Q\nA,Z\nArrow keys\n") _T("F1\nF2\nEsc") ); } else { m_pFontSmall->DrawText( 2, 60, D3DCOLOR_ARGB(255,100,100,200), _T("Press F1 for help") ); } if(FAILED(hr = m_pd3dDevice->EndScene())) return hr; return S_OK; }