//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_ScriptIntro::ClientThink( void ) { Assert( m_IntroData.m_Passes.Count() <= 2 ); if ( m_hCameraEntity ) { m_IntroData.m_vecCameraView = m_hCameraEntity->GetAbsOrigin(); m_IntroData.m_vecCameraViewAngles = m_hCameraEntity->GetAbsAngles(); } CalculateFOV(); CalculateAlpha(); // Calculate the blend levels of each pass float flPerc = 1.0; if ( (m_flNextBlendTime - m_flBlendStartTime) != 0 ) { flPerc = clamp( (gpGlobals->curtime - m_flBlendStartTime) / (m_flNextBlendTime - m_flBlendStartTime), 0, 1 ); } // Detect when we're finished blending if ( flPerc >= 1.0 ) { if ( m_IntroData.m_Passes.Count() == 2 ) { // We're done blending m_IntroData.m_Passes[0].m_BlendMode = m_IntroData.m_Passes[1].m_BlendMode; m_IntroData.m_Passes[0].m_Alpha = 1.0; m_IntroData.m_Passes.Remove(1); //Msg("FINISHED BLEND.\n"); } return; } /* if ( m_flNextBlendTime >= gpGlobals->curtime ) { Msg("INTRO BLENDING: Blending from mode %d to %d.\n", m_IntroData.m_Passes[0].m_BlendMode, m_IntroData.m_Passes[1].m_BlendMode ); Msg(" curtime %.2f StartedAt %.2f FinishAt: %.2f\n", gpGlobals->curtime, m_flBlendStartTime, m_flNextBlendTime ); Msg(" Perc: %.2f\n", flPerc ); } */ if ( m_IntroData.m_Passes.Count() == 2 ) { m_IntroData.m_Passes[0].m_Alpha = 1.0 - flPerc; m_IntroData.m_Passes[1].m_Alpha = flPerc; } else { m_IntroData.m_Passes[0].m_Alpha = 1.0 - flPerc; } }
void Screen3D::SetViewTransform ( Matrix& M, bool CalcFOV ) { if(!D3DDevice) return; D3DXMATRIX Inverse; Real Determinant; Inverse = M.Mat; D3DXMatrixInverse(&Inverse, &Determinant, &M.Mat); D3DDevice->SetTransform( D3DTS_VIEW, &M.Mat); if(CalcFOV) CalculateFOV();//calculate the new frustum planes }
bool Screen3D::Create(HWND hwnd, DisplayModeInfo& m, float viewdistance) { if( NULL == ( D3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) return false; D3DDISPLAYMODE d3ddm; if( FAILED( D3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) ) return false; hWnd = hwnd; //Get the client rectangle dimensions of the window. RECT WindowRect; GetClientRect(hwnd, &WindowRect); if( m.Width == -1 || m.Height == -1) { DisplayMode.Width = WindowRect.right - WindowRect.left; DisplayMode.Height = WindowRect.bottom - WindowRect.top; } else { DisplayMode.Width = m.Width; DisplayMode.Height = m.Height; } OutputMessage( "Attempting Resolution: %dx%d\n", DisplayMode.Width, DisplayMode.Height); // Set up the structure used to create the D3DDevice. ZeroMemory( &d3dpp, sizeof(d3dpp) ); if ( DisplayMode.Fullscreen ) { d3dpp.Windowed = FALSE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //D3DSWAPEFFECT_COPY ; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;//D3DPRESENT_INTERVAL_ONE ; d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT ; } else { d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; } d3dpp.BackBufferWidth = DisplayMode.Width ; d3dpp.BackBufferHeight = DisplayMode.Height; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; OutputMessage( "BackBuffer: %d\n", d3ddm.Format ); //Get the depth/stencil caps //check for 32bit depth buffer if( SUCCEEDED ( D3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32) )) { d3dpp.AutoDepthStencilFormat = D3DFMT_D32; } //second choice is 24bit buffer with 8 bit stencil else if( SUCCEEDED ( D3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8) )) { d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; } //third choice is 24bit buffer with 4 bit stencil else if( SUCCEEDED ( D3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X4S4) )) { d3dpp.AutoDepthStencilFormat = D3DFMT_D24X4S4; } //fourth choice is 24bit buffer with 8 bits wasted else if( SUCCEEDED ( D3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8) )) { d3dpp.AutoDepthStencilFormat = D3DFMT_D24X8; } //fifth choice is 16bit buffer else if( SUCCEEDED ( D3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16) ) ) { d3dpp.AutoDepthStencilFormat = D3DFMT_D16; } //last choice is 15bit depth buffer with 1 bit stencil else if( SUCCEEDED ( D3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D15S1) ) ) { d3dpp.AutoDepthStencilFormat = D3DFMT_D15S1; } OutputMessage( "DepthStencil: %d\n", d3dpp.AutoDepthStencilFormat ); // Create the D3DDevice HRESULT hr; DWORD VertexFlags=0; if(true) VertexFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; else VertexFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; // Set default settings //UINT AdapterToUse=D3DADAPTER_DEFAULT; //D3D->GetAdapterCount()-1 //D3DDEVTYPE DeviceType=D3DDEVTYPE_HAL; //D3DDEVTYPE_REF #ifdef NVPERFHUD UINT AdapterToUse=D3D->GetAdapterCount()-1; D3DDEVTYPE DeviceType=D3DDEVTYPE_REF; #else UINT AdapterToUse=D3DADAPTER_DEFAULT; //D3D->GetAdapterCount()-1 D3DDEVTYPE DeviceType=D3DDEVTYPE_HAL; //D3DDEVTYPE_REF #endif // Look for 'NVIDIA NVPerfHUD' adapter // If it is present, override default settings for (UINT Adapter=0;Adapter<D3D->GetAdapterCount();Adapter++) { D3DADAPTER_IDENTIFIER9 Identifier; HRESULT Res; Res = D3D->GetAdapterIdentifier(Adapter,0,&Identifier); if (strcmp(Identifier.Description,"NVIDIA NVPerfHUD") == 0) { AdapterToUse=Adapter; DeviceType=D3DDEVTYPE_REF; break; } } if( FAILED( hr = D3D->CreateDevice( AdapterToUse,//D3DADAPTER_DEFAULT, DeviceType,//D3DDEVTYPE_HAL, hwnd, VertexFlags , &d3dpp, &D3DDevice ) ) ) { OutputDXError( hr, "D3D Device Init Failed "); return false; } else { //We have a mixed device, so figure out the level of T&L support D3DCAPS9 tlcaps; D3DDevice->GetDeviceCaps(&tlcaps); // initialize m_pd3dDevice before using //check the shader version if( D3DSHADER_VERSION_MAJOR( tlcaps.VertexShaderVersion ) < 1 ) TLSupport = S3D_STANDARD; //Major version is 1, so check minor versions else if(D3DSHADER_VERSION_MINOR( tlcaps.VertexShaderVersion ) < 1 ) TLSupport = S3D_VS_1_0; //Vertex shader 1.0 else TLSupport = S3D_VS_1_1; //Vertex shader 1.1 or above } //set up the projection matrix D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, RADIAN(60), (float)DisplayMode.Width/(float)DisplayMode.Height, 1.0f, viewdistance ); D3DDevice->SetTransform( D3DTS_PROJECTION, &matProj ); //figure out the field of view CalculateFOV(); // initial render state D3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); D3DDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); D3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); D3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); D3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); D3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); D3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); D3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); D3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); SetLinearTextureFiltering(); //init the texture manager TM.Init(this); TM.RestoreTextures(); InitialAvailableMem = D3DDevice->GetAvailableTextureMem(); //Init the font manager FM.Init( *this ); //return OK return true; }