//------------------------------------------------------------- // Name: RestoreDeviceObjects() // Desc: 화면크기가 변했을때 호출됨 // 확보한 메모리는 InvalidateDeviceObjects()에서 해제 //------------------------------------------------------------- HRESULT CMyD3DApplication::RestoreDeviceObjects() { // 정점과 색정보 CUSTOMVERTEX vertices[] = { // x, y, z, {-0.5f, +0.5f, 0}, {+0.5f, +0.5f, 0}, {-0.5f, -0.5f, 0}, {+0.5f, -0.5f, 0}, }; // 정점버퍼 생성 if( FAILED( m_pd3dDevice->CreateVertexBuffer( 4*sizeof(CUSTOMVERTEX), // 정점버퍼 크기 0, D3DFVF_CUSTOMVERTEX, // 사용법, 정점포맷 D3DPOOL_DEFAULT, // 메모리 클래스 &m_pVB, NULL ))) // 정점버퍼 리소스 return E_FAIL; // 정점버퍼에 정보 저장 VOID* pVertices; if(FAILED( m_pVB->Lock(0, sizeof(vertices), (void**)&pVertices, 0))) return E_FAIL; memcpy( pVertices, vertices, sizeof(vertices) ); m_pVB->Unlock(); // 단축매크로 #define RS m_pd3dDevice->SetRenderState #define TSS m_pd3dDevice->SetTextureStageState #define SAMP m_pd3dDevice->SetSamplerState // 렌더링 상태설정 RS( D3DRS_DITHERENABLE, FALSE ); RS( D3DRS_SPECULARENABLE, FALSE ); RS( D3DRS_ZENABLE, TRUE ); RS( D3DRS_AMBIENT, 0x000F0F0F ); TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE ); // 폰트 m_pFont->RestoreDeviceObjects(); // 뷰행렬 설정 D3DXVECTOR3 vEye = D3DXVECTOR3( 0.0f, 0.0f, 1.0f ); D3DXVECTOR3 vAt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUp = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); D3DXMatrixLookAtRH( &m_matView, &vEye, &vAt, &vUp ); // 투영행렬 설정 FLOAT fAspectRatio = (FLOAT)m_d3dsdBackBuffer.Width / (FLOAT)m_d3dsdBackBuffer.Height; D3DXMatrixPerspectiveFovRH( &m_matProj, D3DXToRadian(60.0f), fAspectRatio, 0.1f, 100.0f ); return S_OK; }
//------------------------------------------------------------- // Name: RestoreDeviceObjects() // Desc: 화면크기가 변했을때 호출됨 // 확보한 메모리는 InvalidateDeviceObjects()에서 해제 //------------------------------------------------------------- HRESULT CMyD3DApplication::RestoreDeviceObjects() { // 메시 m_pMesh ->RestoreDeviceObjects( m_pd3dDevice ); m_pMeshBg->RestoreDeviceObjects( m_pd3dDevice ); // 셰이더 m_pEffect->OnResetDevice(); // 재질설정 D3DMATERIAL9 mtrl; D3DUtil_InitMaterial( mtrl, 1.0f, 0.0f, 0.0f ); m_pd3dDevice->SetMaterial( &mtrl ); // 렌더링 상태설정 RS( D3DRS_DITHERENABLE, FALSE ); RS( D3DRS_SPECULARENABLE, FALSE ); RS( D3DRS_ZENABLE, TRUE ); RS( D3DRS_AMBIENT, 0x000F0F0F ); RS( D3DRS_LIGHTING, TRUE ); TSS( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); TSS( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); TSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); SAMP( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); SAMP( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); SAMP( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); SAMP( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); // 월드행렬 D3DXMATRIX matIdentity; D3DXMatrixIdentity( &m_mWorld ); // 뷰행렬 D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -5.0f ); D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); D3DXMatrixLookAtLH( &m_mView, &vFromPt, &vLookatPt, &vUpVec ); // 투영행렬 FLOAT fAspect = ((FLOAT)m_d3dsdBackBuffer.Width) / m_d3dsdBackBuffer.Height; D3DXMatrixPerspectiveFovLH( &m_mProj, D3DX_PI/4, fAspect, 1.0f, 100.0f ); // 폰트 m_pFont->RestoreDeviceObjects(); return S_OK; }
static bool addAllCoggan() { RideMetricFactory::instance().addMetric(NP()); QVector<QString> deps; deps.append("coggan_np"); RideMetricFactory::instance().addMetric(IntensityFactor(), &deps); deps.append("coggan_if"); RideMetricFactory::instance().addMetric(TSS(), &deps); deps.clear(); deps.append("coggan_np"); deps.append("average_power"); RideMetricFactory::instance().addMetric(VI(), &deps); deps.clear(); deps.append("coggan_np"); deps.append("average_hr"); RideMetricFactory::instance().addMetric(EfficiencyFactor(), &deps); return true; }
//------------------------------------------------------------- // Name: Render() // Desc: 화면 렌더 //------------------------------------------------------------- HRESULT CMyD3DApplication::Render() { D3DXMATRIX m, mT, mR, mL, mView, mProj; D3DXVECTOR4 v, light_pos; D3DMATERIAL9 *pMtrl; DWORD i; //--------------------------------------------------------- // 렌더 //--------------------------------------------------------- if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { m_pd3dDevice->Clear(0L, NULL , D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , D3DCOLOR_RGBA(0,0,0,0), 1.0f, 0L); //------------------------------------------------- // 그냥 평범하게 렌더 //------------------------------------------------- m_pd3dDevice->SetTransform( D3DTS_WORLD, &m_mWorld); m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_mView ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &m_mProj ); TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); m_pMeshBg->Render( m_pd3dDevice ); // 비행모델 렌더 TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE ); TSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE ); //------------------------------------------------- // 확대한 모델 출력 //------------------------------------------------- if( m_pEffect != NULL ) { m_pEffect->SetTechnique( m_hTechnique ); m_pEffect->Begin( NULL, 0 ); // 로컬-월드 행렬 D3DXMatrixTranslation( &m, 1.0f, 0.0f ,0.0f ); D3DXMatrixRotationY( &mR, 3.0f*m_fTime ); D3DXMatrixTranslation( &mT, 1.0f, 1.0f ,0.0f ); mL = m * mR * mT * m_mWorld; // 광원방향 D3DXMatrixInverse( &m, NULL, &mL); light_pos = D3DXVECTOR4(1,1,-1,0); D3DXVec4Transform( &v, &light_pos, &m ); v.w = 0; D3DXVec4Normalize( &v, &v ); m_pEffect->SetVector( m_hvLightDir, &v ); // 시점 D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -m_fViewZoom ); D3DXVec3Transform( &v, &vFromPt, &m ); m_pEffect->SetVector( m_hvEyePos, &v ); // 로컬-투영변환행렬 m = mL * m_mView; m_pEffect->SetMatrix( m_hmWV, &m ); m_pEffect->SetMatrix( m_hmVP, &m_mProj ); // 1프레임 직전 행렬 m_pEffect->SetMatrix( m_hmLastWV, &m_mLastWV ); m_mLastWV = m; for(int pass = 0; pass<2; pass++){ m_pEffect->Pass( pass );// 패스를 바꿔서 출력 if(1==pass){ RS( D3DRS_ZWRITEENABLE, FALSE); RS( D3DRS_ALPHABLENDENABLE, TRUE); RS( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); RS( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); } pMtrl = m_pMesh->m_pMaterials; for( i=0; i<m_pMesh->m_dwNumMaterials; i++ ) { v.x = pMtrl->Diffuse.r; v.y = pMtrl->Diffuse.g; v.z = pMtrl->Diffuse.b; v.w = pMtrl->Diffuse.a; m_pEffect->SetVector( m_hvCol, &v ); m_pMesh->m_pLocalMesh->DrawSubset( i ); // 렌더 pMtrl++; } } m_pEffect->End(); RS( D3DRS_ALPHABLENDENABLE, FALSE); RS( D3DRS_ZWRITEENABLE, TRUE); } RenderText(); // 도움말 출력 m_pd3dDevice->EndScene(); // 렌더종료 } Sleep(100); return S_OK; }
/// Called by D3D9 device to active this state block. /// @param oldState The current state, used to make sure we don't set redundant states on the device. Pass NULL to reset all states. void GFXD3D9StateBlock::activate(GFXD3D9StateBlock* oldState) { PROFILE_SCOPE( GFXD3D9StateBlock_Activate ); // Little macro to save some typing, SD = state diff, checks for null source state block, then // checks to see if the states differ #if defined(TORQUE_OS_XENON) #define SD(x, y) if (!oldState || oldState->mDesc.x != mDesc.x) \ mD3DDevice->SetRenderState_Inline(y, mDesc.x) // Same as above, but allows you to set the data #define SDD(x, y, z) if (!oldState || oldState->mDesc.x != mDesc.x) \ mD3DDevice->SetRenderState_Inline(y, z) #else #define SD(x, y) if (!oldState || oldState->mDesc.x != mDesc.x) \ mD3DDevice->SetRenderState(y, mDesc.x) // Same as above, but allows you to set the data #define SDD(x, y, z) if (!oldState || oldState->mDesc.x != mDesc.x) \ mD3DDevice->SetRenderState(y, z) #endif // Blending SD(blendEnable, D3DRS_ALPHABLENDENABLE); SDD(blendSrc, D3DRS_SRCBLEND, GFXD3D9Blend[mDesc.blendSrc]); SDD(blendDest, D3DRS_DESTBLEND, GFXD3D9Blend[mDesc.blendDest]); SDD(blendOp, D3DRS_BLENDOP, GFXD3D9BlendOp[mDesc.blendOp]); // Separate alpha blending SD(separateAlphaBlendEnable, D3DRS_SEPARATEALPHABLENDENABLE); SDD(separateAlphaBlendSrc, D3DRS_SRCBLENDALPHA, GFXD3D9Blend[mDesc.separateAlphaBlendSrc]); SDD(separateAlphaBlendDest, D3DRS_DESTBLENDALPHA, GFXD3D9Blend[mDesc.separateAlphaBlendDest]); SDD(separateAlphaBlendOp, D3DRS_BLENDOPALPHA, GFXD3D9BlendOp[mDesc.separateAlphaBlendOp]); // Alpha test SD(alphaTestEnable, D3DRS_ALPHATESTENABLE); SDD(alphaTestFunc, D3DRS_ALPHAFUNC, GFXD3D9CmpFunc[mDesc.alphaTestFunc]); SD(alphaTestRef, D3DRS_ALPHAREF); // Color writes if ((oldState == NULL) || (mColorMask != oldState->mColorMask)) mD3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, mColorMask); // Culling SDD(cullMode, D3DRS_CULLMODE, GFXD3D9CullMode[mDesc.cullMode]); // Depth SD(zEnable, D3DRS_ZENABLE); SD(zWriteEnable, D3DRS_ZWRITEENABLE); SDD(zFunc, D3DRS_ZFUNC, GFXD3D9CmpFunc[mDesc.zFunc]); if ((!oldState) || (mZBias != oldState->mZBias)) mD3DDevice->SetRenderState(D3DRS_DEPTHBIAS, mZBias); if ((!oldState) || (mZSlopeBias != oldState->mZSlopeBias)) mD3DDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, mZSlopeBias); // Stencil SD(stencilEnable, D3DRS_STENCILENABLE); SDD(stencilFailOp, D3DRS_STENCILFAIL, GFXD3D9StencilOp[mDesc.stencilFailOp]); SDD(stencilZFailOp, D3DRS_STENCILZFAIL, GFXD3D9StencilOp[mDesc.stencilZFailOp]); SDD(stencilPassOp, D3DRS_STENCILPASS, GFXD3D9StencilOp[mDesc.stencilPassOp]); SDD(stencilFunc, D3DRS_STENCILFUNC, GFXD3D9CmpFunc[mDesc.stencilFunc]); SD(stencilRef, D3DRS_STENCILREF); SD(stencilMask, D3DRS_STENCILMASK); SD(stencilWriteMask, D3DRS_STENCILWRITEMASK); SDD(fillMode, D3DRS_FILLMODE, GFXD3D9FillMode[mDesc.fillMode]); #if !defined(TORQUE_OS_XENON) SD(ffLighting, D3DRS_LIGHTING); SD(vertexColorEnable, D3DRS_COLORVERTEX); static DWORD swzTemp; getOwningDevice()->getDeviceSwizzle32()->ToBuffer( &swzTemp, &mDesc.textureFactor, sizeof(ColorI) ); SDD(textureFactor, D3DRS_TEXTUREFACTOR, swzTemp); #endif #undef SD #undef SDD // NOTE: Samplers and Stages are different things. // // The Stages were for fixed function blending. When using shaders // calling SetTextureStageState() is a complete waste of time. In // fact if this function rises to the top of profiles we should // refactor stateblocks to seperate the two. // // Samplers are used by both fixed function and shaders, but the // number of samplers is limited by shader model. #if !defined(TORQUE_OS_XENON) #define TSS(x, y, z) if (!oldState || oldState->mDesc.samplers[i].x != mDesc.samplers[i].x) \ mD3DDevice->SetTextureStageState(i, y, z) for ( U32 i = 0; i < 8; i++ ) { TSS(textureColorOp, D3DTSS_COLOROP, GFXD3D9TextureOp[mDesc.samplers[i].textureColorOp]); TSS(colorArg1, D3DTSS_COLORARG1, mDesc.samplers[i].colorArg1); TSS(colorArg2, D3DTSS_COLORARG2, mDesc.samplers[i].colorArg2); TSS(colorArg3, D3DTSS_COLORARG0, mDesc.samplers[i].colorArg3); TSS(alphaOp, D3DTSS_ALPHAOP, GFXD3D9TextureOp[mDesc.samplers[i].alphaOp]); TSS(alphaArg1, D3DTSS_ALPHAARG1, mDesc.samplers[i].alphaArg1); TSS(alphaArg2, D3DTSS_ALPHAARG2, mDesc.samplers[i].alphaArg2); TSS(alphaArg3, D3DTSS_ALPHAARG0, mDesc.samplers[i].alphaArg3); TSS(textureTransform, D3DTSS_TEXTURETRANSFORMFLAGS, mDesc.samplers[i].textureTransform); TSS(resultArg, D3DTSS_RESULTARG, mDesc.samplers[i].resultArg); } #undef TSS #endif #if defined(TORQUE_OS_XENON) #define SS(x, y, z) if (!oldState || oldState->mDesc.samplers[i].x != mDesc.samplers[i].x) \ mD3DDevice->SetSamplerState_Inline(i, y, z) #else #define SS(x, y, z) if (!oldState || oldState->mDesc.samplers[i].x != mDesc.samplers[i].x) \ mD3DDevice->SetSamplerState(i, y, z) #endif for ( U32 i = 0; i < getOwningDevice()->getNumSamplers(); i++ ) { SS(minFilter, D3DSAMP_MINFILTER, GFXD3D9TextureFilter[mDesc.samplers[i].minFilter]); SS(magFilter, D3DSAMP_MAGFILTER, GFXD3D9TextureFilter[mDesc.samplers[i].magFilter]); SS(mipFilter, D3DSAMP_MIPFILTER, GFXD3D9TextureFilter[mDesc.samplers[i].mipFilter]); F32 bias = mDesc.samplers[i].mipLODBias; DWORD dwBias = *( (LPDWORD)(&bias) ); SS(mipLODBias, D3DSAMP_MIPMAPLODBIAS, dwBias); SS(maxAnisotropy, D3DSAMP_MAXANISOTROPY, mDesc.samplers[i].maxAnisotropy); SS(addressModeU, D3DSAMP_ADDRESSU, GFXD3D9TextureAddress[mDesc.samplers[i].addressModeU]); SS(addressModeV, D3DSAMP_ADDRESSV, GFXD3D9TextureAddress[mDesc.samplers[i].addressModeV]); SS(addressModeW, D3DSAMP_ADDRESSW, GFXD3D9TextureAddress[mDesc.samplers[i].addressModeW]); } #undef SS }
//------------------------------------------------------------- // Name: Render() // Desc: 화면 렌더 //------------------------------------------------------------- HRESULT CMyD3DApplication::Render() { D3DXMATRIX m, mT, mR, mL, mView, mProj; D3DXVECTOR4 v, light_pos; D3DMATERIAL9 *pMtrl; LPDIRECT3DSURFACE9 pOldBackBuffer, pOldZBuffer; D3DVIEWPORT9 oldViewport; DWORD i; // 뷰포트 D3DVIEWPORT9 viewport = {0,0 // 좌측상단 , MAP_WIDTH // 폭 , MAP_HEIGHT // 높이 , 0.0f,1.0f}; // 전면,후면 //------------------------------------------------- // 렌더링타겟 보존 //------------------------------------------------- m_pd3dDevice->GetRenderTarget(0, &pOldBackBuffer); m_pd3dDevice->GetDepthStencilSurface(&pOldZBuffer); m_pd3dDevice->GetViewport(&oldViewport); TVERTEX Vertex[4] = { // x y z rhw tu tv { 0, 0,0, 1, 0, 0,}, {oldViewport.Width, 0,0, 1, 1, 0,}, {oldViewport.Width,oldViewport.Height,0, 1, 1, 1,}, { 0,oldViewport.Height,0, 1, 0, 1,}, }; //--------------------------------------------------------- // 렌더 //--------------------------------------------------------- if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { // 렌더링타겟 변경 m_pd3dDevice->SetRenderTarget(0, m_pSurfBg); m_pd3dDevice->SetDepthStencilSurface(m_pZBg); m_pd3dDevice->SetViewport(&viewport); m_pd3dDevice->Clear(0L, NULL , D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , D3DCOLOR_RGBA(0,0,0,0), 1.0f, 0L); //------------------------------------------------- // 배경렌더 //------------------------------------------------- m_pd3dDevice->SetTransform( D3DTS_WORLD, &m_mWorld); m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_mView ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &m_mProj ); TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); m_pMeshBg->Render( m_pd3dDevice ); //------------------------------------------------- // 배경을 프레임버퍼에 렌더 //------------------------------------------------- // 렌더링타겟 복구 m_pd3dDevice->SetRenderTarget(0, pOldBackBuffer); m_pd3dDevice->SetDepthStencilSurface(pOldZBuffer); m_pd3dDevice->SetViewport(&oldViewport); RS( D3DRS_ZENABLE, FALSE); m_pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 ); m_pd3dDevice->SetTexture( 0, m_pTexBg ); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN , 2, Vertex, sizeof( TVERTEX ) ); RS( D3DRS_ZENABLE, TRUE); // 비행모델 렌더 TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE ); TSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE ); if( m_pEffect != NULL ) { m_pEffect->SetTechnique( m_hTechnique ); m_pEffect->Begin( NULL, 0 ); // 로컬-월드 행렬 D3DXMatrixTranslation( &m, 1.0f, 0.0f ,0.0f ); D3DXMatrixRotationY( &mR, m_fTime ); D3DXMatrixTranslation( &mT, 1.0f, 1.0f ,0.0f ); mL = m * mR * mT * m_mWorld; // 광원방향 D3DXMatrixInverse( &m, NULL, &mL); light_pos = D3DXVECTOR4(1,1,-1,0); D3DXVec4Transform( &v, &light_pos, &m ); v.w = 0; D3DXVec4Normalize( &v, &v ); m_pEffect->SetVector( m_hvLightDir, &v ); // 시점 D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -m_fViewZoom ); D3DXVec3Transform( &v, &vFromPt, &m ); m_pEffect->SetVector( m_hvEyePos, &v ); // 로컬-투영변환행렬 m = mL * m_mView; m_pEffect->SetMatrix( m_hmWV, &m ); m_pEffect->SetMatrix( m_hmVP, &m_mProj ); // 1프레임 직전 행렬 m_pEffect->SetMatrix( m_hmLastWV, &m_mLastWV ); m_mLastWV = m; for(int pass = 0; pass<2; pass++){ m_pEffect->Pass( pass );// 패스를 바꿔서 출력 switch(pass){ case 0: // 렌더링타겟 변경 m_pd3dDevice->SetRenderTarget(0, m_pSurfObj); m_pd3dDevice->SetDepthStencilSurface(m_pZObj); m_pd3dDevice->Clear(0L, NULL , D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , D3DCOLOR_RGBA(0,0,0,0), 1.0f, 0L); break; case 1: // 렌더링타겟 변경 m_pd3dDevice->SetRenderTarget(0, m_pSurfBg); m_pd3dDevice->SetDepthStencilSurface(m_pZBg); m_pd3dDevice->Clear(0L, NULL , D3DCLEAR_TARGET , D3DCOLOR_RGBA(0,0,0,0), 1.0f, 0L); m_pEffect->SetTexture(m_htSrcMap, m_pTexObj); break; } // 모델렌더 pMtrl = m_pMesh->m_pMaterials; for( i=0; i<m_pMesh->m_dwNumMaterials; i++ ) { v.x = pMtrl->Diffuse.r; v.y = pMtrl->Diffuse.g; v.z = pMtrl->Diffuse.b; v.w = pMtrl->Diffuse.a; m_pEffect->SetVector( m_hvCol, &v ); m_pMesh->m_pLocalMesh->DrawSubset( i ); // 렌더 pMtrl++; } } m_pEffect->End(); } // 렌더링타겟 복구 m_pd3dDevice->SetRenderTarget(0, pOldBackBuffer); m_pd3dDevice->SetDepthStencilSurface(pOldZBuffer); m_pd3dDevice->SetViewport(&oldViewport); // 생성한 화면 합성 RS( D3DRS_ZENABLE, FALSE); RS( D3DRS_ALPHABLENDENABLE, TRUE); RS( D3DRS_SRCBLEND, D3DBLEND_ONE); RS( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); TSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); m_pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 ); m_pd3dDevice->SetTexture( 0, m_pTexBg ); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN , 2, Vertex, sizeof( TVERTEX ) ); RS( D3DRS_ZENABLE, TRUE); RS( D3DRS_ALPHABLENDENABLE, FALSE); RenderText(); // 도움말 출력 #if 0 // 디버그용 텍스처 출력 { m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); m_pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_DISABLE); m_pd3dDevice->SetVertexShader(NULL); m_pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 ); m_pd3dDevice->SetPixelShader(0); float scale = 128.0f; for(DWORD i=0; i<2; i++){ TVERTEX Vertex[4] = { // x y z rhw tu tv { 0,(i+0)*scale,0, 1, 0, 0,}, {scale,(i+0)*scale,0, 1, 1, 0,}, {scale,(i+1)*scale,0, 1, 1, 1,}, { 0,(i+1)*scale,0, 1, 0, 1,}, }; if(0==i) m_pd3dDevice->SetTexture( 0, m_pTexObj ); if(1==i) m_pd3dDevice->SetTexture( 0, m_pTexBg ); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, Vertex, sizeof( TVERTEX ) ); } } #endif m_pd3dDevice->EndScene(); // 렌더종료 } pOldBackBuffer->Release(); pOldZBuffer->Release(); Sleep(50); return S_OK; }
//------------------------------------------------------------- // Name: RestoreDeviceObjects() // Desc: 화면크기가 변했을때 호출됨 // 확보한 메모리는 InvalidateDeviceObjects()에서 해제 //------------------------------------------------------------- HRESULT CMyD3DApplication::RestoreDeviceObjects() { // 메시 m_pMesh ->RestoreDeviceObjects( m_pd3dDevice ); m_pMeshBg->RestoreDeviceObjects( m_pd3dDevice ); // 셰이더 m_pEffect->OnResetDevice(); // 재질설정 D3DMATERIAL9 mtrl; D3DUtil_InitMaterial( mtrl, 1.0f, 0.0f, 0.0f ); m_pd3dDevice->SetMaterial( &mtrl ); // 렌더링 상태설정 RS( D3DRS_DITHERENABLE, FALSE ); RS( D3DRS_SPECULARENABLE, FALSE ); RS( D3DRS_ZENABLE, TRUE ); RS( D3DRS_AMBIENT, 0x000F0F0F ); RS( D3DRS_LIGHTING, TRUE ); TSS( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); TSS( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); TSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); SAMP( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); SAMP( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); SAMP( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); SAMP( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); // 월드행렬 D3DXMATRIX matIdentity; D3DXMatrixIdentity( &m_mWorld ); // 뷰행렬 D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -5.0f ); D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); D3DXMatrixLookAtLH( &m_mView, &vFromPt, &vLookatPt, &vUpVec ); // 투영행렬 FLOAT fAspect = ((FLOAT)m_d3dsdBackBuffer.Width) / m_d3dsdBackBuffer.Height; D3DXMatrixPerspectiveFovLH( &m_mProj, D3DX_PI/4, fAspect, 1.0f, 100.0f ); // 폰트 m_pFont->RestoreDeviceObjects(); // 렌더링타겟 생성 if (FAILED(m_pd3dDevice->CreateDepthStencilSurface( MAP_WIDTH, MAP_HEIGHT, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, TRUE, &m_pZBg, NULL))) return E_FAIL; if (FAILED(m_pd3dDevice->CreateTexture( MAP_WIDTH, MAP_HEIGHT, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pTexBg, NULL))) return E_FAIL; if (FAILED(m_pTexBg->GetSurfaceLevel(0, &m_pSurfBg))) return E_FAIL; if (FAILED(m_pd3dDevice->CreateDepthStencilSurface( MAP_WIDTH, MAP_HEIGHT, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, TRUE, &m_pZObj, NULL))) return E_FAIL; if (FAILED(m_pd3dDevice->CreateTexture( MAP_WIDTH, MAP_HEIGHT, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pTexObj, NULL))) return E_FAIL; if (FAILED(m_pTexObj->GetSurfaceLevel(0, &m_pSurfObj))) return E_FAIL; return S_OK; }
//------------------------------------------------------------- // Name: Render() // Desc: 화면 렌더 //------------------------------------------------------------- HRESULT CMyD3DApplication::Render() { D3DXMATRIX m, mT, mR, mView, mProj; D3DXMATRIX mWorld; D3DXVECTOR4 v, light_pos, eye_pos; DWORD i; //--------------------------------------------------------- // 렌더 //--------------------------------------------------------- if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { // 렌더링 타겟 클리어 m_pd3dDevice->Clear(0L, NULL , D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , 0x0060c0, 1.0f, 0L); //----------------------------------------------------- // 지형렌더 //----------------------------------------------------- // 월드행렬 D3DXMatrixScaling( &m, 3.0f, 3.0f, 3.0f ); D3DXMatrixRotationY( &mR, D3DX_PI ); D3DXMatrixTranslation( &mT, 0.0f,-2.0f ,0.0f ); mWorld = m * mR * mT; // 행렬설정 m_pd3dDevice->SetTransform( D3DTS_WORLD, &mWorld); m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_mView ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &m_mProj ); TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); m_pMeshBg->Render( m_pd3dDevice ); if( m_pEffect != NULL ) { //------------------------------------------------- // 셰이더 설정 //------------------------------------------------- m_pEffect->SetTechnique( m_hTechnique ); m_pEffect->Begin( NULL, 0 ); m_pEffect->Pass( 0 ); //------------------------------------------------- // 주전자 렌더 //------------------------------------------------- // 월드행렬(회전) D3DXMatrixRotationY( &mWorld, m_fTime ); // 로컬-투영 변환행렬 m = mWorld * m_mView * m_mProj; m_pEffect->SetMatrix( m_hmWVP, &m ); // 광원의 방향(로컬좌표계) light_pos = D3DXVECTOR4( -0.577f, -0.577f, -0.577f,0); D3DXMatrixInverse( &m, NULL, &mWorld); D3DXVec4Transform( &v, &light_pos, &m ); D3DXVec3Normalize( (D3DXVECTOR3 *)&v, (D3DXVECTOR3 *)&v ); v.w = -0.7f; // 환경광 강도 m_pEffect->SetVector( m_hvLightDir, &v ); // 시점(로컬좌표계) m = mWorld * m_mView; D3DXMatrixInverse( &m, NULL, &m); v = D3DXVECTOR4( 0, 0, 0, 1); D3DXVec4Transform( &v, &v, &m ); m_pEffect->SetVector( m_hvEyePos, &v ); // 법선맵 m_pEffect->SetTexture( m_htNormalMap, m_pNormalMap ); // 정점선언 m_pd3dDevice->SetVertexDeclaration( m_pDecl ); D3DMATERIAL9 *pMtrl = m_pMesh->m_pMaterials; for( i=0; i<m_pMesh->m_dwNumMaterials; i++ ) { v.x = pMtrl->Diffuse.r; v.y = pMtrl->Diffuse.g; v.z = pMtrl->Diffuse.b; m_pEffect->SetVector( m_hvColor, &v ); m_pEffect->SetTexture( m_htDecaleTex, m_pMesh->m_pTextures[i] ); m_pMesh->m_pLocalMesh->DrawSubset( i ); // 렌더 pMtrl++; } m_pEffect->End(); } // 도움말 출력 RenderText(); // 렌더종료 m_pd3dDevice->EndScene(); } return S_OK; }
//------------------------------------------------------------- // Name: RenderScene() // Desc: ȭ�� ���� //------------------------------------------------------------- void CMyD3DApplication::RenderScene() { D3DXMATRIX m, mT, mR, mView, mProj; D3DXMATRIX mWorld; D3DXVECTOR4 v, light_pos, eye_pos; DWORD i; //----------------------------------------------------- // �������� //----------------------------------------------------- // ������� D3DXMatrixScaling( &m, 3.0f, 3.0f, 3.0f ); D3DXMatrixRotationY( &mR, D3DX_PI ); D3DXMatrixTranslation( &mT, 0.0f,-2.0f ,0.0f ); mWorld = m * mR * mT; // ��ļ��� m_pd3dDevice->SetTransform( D3DTS_WORLD, &mWorld); m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_mView ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &m_mProj ); TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); SAMP( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); SAMP( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); m_pMeshBg->Render( m_pd3dDevice ); if( m_pEffect != NULL ) { //------------------------------------------------- // ���̴� ���� //------------------------------------------------- m_pEffect->SetTechnique( m_hTechnique ); m_pEffect->Begin( NULL, 0 ); m_pEffect->Pass( 0 ); //------------------------------------------------- // ������ ���� //------------------------------------------------- // �������(ȸ��) D3DXMatrixRotationY( &mWorld, m_fTime ); // ����-������ȯ��� m = mWorld * m_mView * m_mProj; m_pEffect->SetMatrix( m_hmWVP, &m ); // ��������(������ǥ��) light_pos = D3DXVECTOR4( -0.577f, -0.577f, -0.577f,0); D3DXMatrixInverse( &m, NULL, &mWorld); D3DXVec4Transform( &v, &light_pos, &m ); D3DXVec3Normalize( (D3DXVECTOR3 *)&v, (D3DXVECTOR3 *)&v ); v.w = -0.5f; // ȯ�汤��� m_pEffect->SetVector( m_hvLightDir, &v ); // ����(������ǥ��) m = mWorld * m_mView; D3DXMatrixInverse( &m, NULL, &m); v = D3DXVECTOR4( 0, 0, 0, 1); D3DXVec4Transform( &v, &v, &m ); m_pEffect->SetVector( m_hvEyePos, &v ); // ������ m_pEffect->SetTexture( m_htNormalMap, m_pNormalMap ); // �������� m_pd3dDevice->SetVertexDeclaration( m_pDecl ); D3DMATERIAL9 *pMtrl = m_pMesh->m_pMaterials; for( i=0; i<m_pMesh->m_dwNumMaterials; i++ ) { v.x = pMtrl->Diffuse.r; v.y = pMtrl->Diffuse.g; v.z = pMtrl->Diffuse.b; m_pEffect->SetVector( m_hvColor, &v ); m_pEffect->SetTexture( m_htDecaleTex, m_pMesh->m_pTextures[i] ); m_pMesh->m_pLocalMesh->DrawSubset( i ); // ���� pMtrl++; } m_pEffect->End(); } }
//------------------------------------------------------------- // Name: Render() // Desc: ȭ�� ���� //------------------------------------------------------------- HRESULT CMyD3DApplication::Render() { D3DXMATRIX m, mW, mS, mR, mT; D3DXVECTOR4 v; // ȭ��Ŭ���� m_pd3dDevice->Clear( 0L, NULL , D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL // �� ���� ���ٽ� , 0xffffff, 1.0f, 0L ); // ���� ���� if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { // ---------------------------------------------------- // �غ�:���� ���ºκ� ���� // ---------------------------------------------------- D3DXMatrixIdentity( &m ); m_pd3dDevice->SetTransform( D3DTS_WORLD, &m ); m_pMeshBG->Render( m_pd3dDevice ); // ���� ���� D3DXMatrixScaling( &mS, 1.82f,1.65f, 1.82f ); D3DXMatrixRotationY( &mR, 0.59f*D3DX_PI ); D3DXMatrixTranslation( &mT, 2.73f-1.85f, 0.f , 1.69f ); m = mS * mR * mT; m_pd3dDevice->SetTransform( D3DTS_WORLD, &m ); m_pMeshBox->Render( m_pd3dDevice ); // ū ���� D3DXMatrixScaling( &mS, 1.69f, 3.30f, 1.69f ); D3DXMatrixRotationY( &mR, 0.91f*D3DX_PI ); D3DXMatrixTranslation( &mT, 2.73f-3.685f, 0, 3.51f ); m = mS * mR * mT; m_pd3dDevice->SetTransform( D3DTS_WORLD, &m ); m_pMeshBox->Render( m_pd3dDevice ); // ---------------------------------------------------- // �н�2:���� ���� ���� // ---------------------------------------------------- // ���̹��ۿ� ������� RS( D3DRS_ZWRITEENABLE, FALSE ); // ������Ÿ�ٿ� ������� RS( D3DRS_COLORWRITEENABLE, FALSE ); // �÷����̵� RS( D3DRS_SHADEMODE, D3DSHADE_FLAT ); // ��鷻�� RS( D3DRS_CULLMODE, D3DCULL_NONE ); // ��齺�ٽ� ��� RS( D3DRS_STENCILENABLE, TRUE ); RS( D3DRS_TWOSIDEDSTENCILMODE, TRUE ); // ���ٽ���Ʈ�� �⺻������ �հ�(��Ʈ ���� ����) RS( D3DRS_STENCILFUNC, D3DCMP_ALWAYS ); RS( D3DRS_CCW_STENCILFUNC, D3DCMP_ALWAYS ); // ���ٽǹ����� �������� 1�� ���� RS( D3DRS_STENCILREF, 0x1 ); RS( D3DRS_STENCILMASK, 0xffffffff ); RS( D3DRS_STENCILWRITEMASK, 0xffffffff ); // �ո��� ������Ʈ�� �հ��ϸ� ���ٽǹ����� ������ +1 RS( D3DRS_STENCILPASS, D3DSTENCILOP_INCR ); RS( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP ); RS( D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP ); // ���� ������Ʈ�� �հ��ϸ� ���ٽǹ����� ������ -1 RS( D3DRS_CCW_STENCILPASS, D3DSTENCILOP_DECR ); RS( D3DRS_CCW_STENCILZFAIL, D3DSTENCILOP_KEEP ); RS( D3DRS_CCW_STENCILFAIL, D3DSTENCILOP_KEEP ); // �����Ѵ� if( m_pEffect != NULL ){ D3DXHANDLE hTechnique = m_pEffect->GetTechniqueByName( "TShader" ); m_pEffect->SetTechnique( hTechnique ); m_pEffect->Begin( NULL, 0 ); m_pEffect->Pass( 0 ); // ���� ���� D3DXMatrixScaling( &mS, 1.82f,1.65f, 1.82f ); D3DXMatrixRotationY( &mR, 0.59f*D3DX_PI ); D3DXMatrixTranslation( &mT, 2.73f-1.85f, 0.f , 1.69f ); mW = mS * mR * mT; m = mW * m_mView * m_mProj; if( m_hmWVP != NULL ) m_pEffect->SetMatrix( m_hmWVP, &m ); D3DXMatrixInverse( &m, NULL, &mW); D3DXVec3Transform( &v, &m_LighPos, &m ); if( m_hvPos != NULL ) m_pEffect->SetVector( m_hvPos, &v ); m_pShadowBox->Render( m_pd3dDevice ); // ū ���� D3DXMatrixScaling( &mS, 1.69f, 3.30f, 1.69f ); D3DXMatrixRotationY( &mR, 0.91f*D3DX_PI ); D3DXMatrixTranslation( &mT, 2.73f-3.685f, 0, 3.51f ); mW = mS * mR * mT; m = mW * m_mView * m_mProj; if( m_hmWVP != NULL ) m_pEffect->SetMatrix( m_hmWVP, &m ); D3DXMatrixInverse( &m, NULL, &mW); D3DXVec3Transform( &v, &m_LighPos, &m ); if( m_hvPos != NULL ) m_pEffect->SetVector( m_hvPos, &v ); m_pShadowBox->Render( m_pd3dDevice ); m_pEffect->End(); } // �������� ���� RS( D3DRS_SHADEMODE, D3DSHADE_GOURAUD ); RS( D3DRS_CULLMODE, D3DCULL_CCW ); RS( D3DRS_ZWRITEENABLE, TRUE ); RS( D3DRS_COLORWRITEENABLE, 0xf ); RS( D3DRS_STENCILENABLE, FALSE ); RS( D3DRS_ALPHABLENDENABLE, FALSE ); RS( D3DRS_TWOSIDEDSTENCILMODE, FALSE ); // ---------------------------------------------------- // �н�3:���� ���� // ---------------------------------------------------- // ������Ʈ ���� RS( D3DRS_ZENABLE, FALSE ); // ���ٽ���Ʈ ��� RS( D3DRS_STENCILENABLE, TRUE ); // ���ĺ����� �����ռ� RS( D3DRS_ALPHABLENDENABLE, TRUE ); RS( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); RS( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); // �������� �������Ҷ� �ؽ�ó�� �������� ��� ��� TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE ); TSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE ); // ���ٽǹ����� ���� 1�̻��� ��쿡�� ���� RS( D3DRS_STENCILREF, 0x1 ); RS( D3DRS_STENCILFUNC, D3DCMP_LESSEQUAL ); RS( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP ); m_pBigSquare->Render( m_pd3dDevice ); // �������� ���� RS( D3DRS_ZENABLE, TRUE ); RS( D3DRS_STENCILENABLE, FALSE ); RS( D3DRS_ALPHABLENDENABLE, FALSE ); RenderText(); // ���� ��� m_pd3dDevice->EndScene(); // �������� } return S_OK; }
//------------------------------------------------------------- // Name: RestoreDeviceObjects() // Desc: ȭ��ũ�Ⱑ �������� ȣ��� // Ȯ���� �� InvalidateDeviceObjects()���� ���� //------------------------------------------------------------- HRESULT CMyD3DApplication::RestoreDeviceObjects() { m_LighPos = D3DXVECTOR3(0.0f, 5.488f, 2.770f); // �������� D3DMATERIAL9 mtrl; D3DUtil_InitMaterial( mtrl, 1.0f, 0.0f, 0.0f ); m_pd3dDevice->SetMaterial( &mtrl ); // �ؽ�ó ���� TSS( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); TSS( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); TSS( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); TSS( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); TSS( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); SAMP( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); SAMP( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); // ������ ���¼��� RS( D3DRS_DITHERENABLE, FALSE ); RS( D3DRS_SPECULARENABLE, FALSE ); RS( D3DRS_ZENABLE, TRUE ); RS( D3DRS_AMBIENT, 0x000F0F0F ); // ������� D3DXMATRIX matIdentity; D3DXMatrixIdentity( &matIdentity ); m_pd3dDevice->SetTransform( D3DTS_WORLD, &matIdentity ); // ����� D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -5.0f ); D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); D3DXMatrixLookAtLH( &m_mView, &vFromPt, &vLookatPt, &vUpVec ); m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_mView ); // ������� FLOAT fAspect = ((FLOAT)m_d3dsdBackBuffer.Width) / m_d3dsdBackBuffer.Height; D3DXMatrixPerspectiveFovLH( &m_mProj, 0.21f*D3DX_PI, fAspect, 1.0f, 100.0f ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &m_mProj ); // �������� D3DLIGHT9 light; D3DUtil_InitLight( light, D3DLIGHT_DIRECTIONAL, -0.0f, -1.0f, 0.2f ); light.Diffuse.r = 0.5f; light.Diffuse.g = 0.5f; light.Diffuse.b = 0.5f; light.Ambient.r = 0.5f; light.Ambient.g = 0.5f; light.Ambient.b = 0.5f; m_pd3dDevice->SetLight( 0, &light ); m_pd3dDevice->LightEnable( 0, TRUE ); m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); // �簢�� m_pBigSquare->RestoreDeviceObjects( (FLOAT)m_d3dsdBackBuffer.Width, (FLOAT)m_d3dsdBackBuffer.Height ); // �� m_pMeshBG->RestoreDeviceObjects(m_pd3dDevice); m_pMeshBox->RestoreDeviceObjects(m_pd3dDevice); // ����Ʈ if( m_pEffect != NULL ) m_pEffect->OnResetDevice(); m_pFont->RestoreDeviceObjects(); // ��Ʈ return S_OK; }
//------------------------------------------------------------- // Name: Render() // Desc: 화면 렌더 //------------------------------------------------------------- HRESULT CMyD3DApplication::Render() { D3DXMATRIX m, mT, mR, mView, mProj; LPDIRECT3DSURFACE9 pOldBackBuffer, pOldZBuffer; D3DVIEWPORT9 oldViewport; //--------------------------------------------------------- // 렌더 //--------------------------------------------------------- if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { //------------------------------------------------- // 렌더링타겟 보존 //------------------------------------------------- m_pd3dDevice->GetRenderTarget(0, &pOldBackBuffer); m_pd3dDevice->GetDepthStencilSurface(&pOldZBuffer); m_pd3dDevice->GetViewport(&oldViewport); if( m_pEffect != NULL ) { //------------------------------------------------- // 렌더링타겟 변경 //------------------------------------------------- m_pd3dDevice->SetRenderTarget(0, m_pOriginalMapSurf); m_pd3dDevice->SetDepthStencilSurface(m_pMapZ); // 뷰포트변경 D3DVIEWPORT9 viewport = {0,0 // 좌측상단 , MAP_WIDTH // 폭 , MAP_HEIGHT // 높이 , 0.0f,1.0f}; // 전면,후면 m_pd3dDevice->SetViewport(&viewport); // 렌더링타겟 클리어 m_pd3dDevice->Clear(0L, NULL , D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , 0xffffffff, 1.0f, 0L); //------------------------------------------------- // 1패스:렌더링타겟 만들기 //------------------------------------------------- m_pd3dDevice->SetTransform( D3DTS_WORLD, &m_mWorld); m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_mView ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &m_mProj ); TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); m_pMeshBg->Render( m_pd3dDevice ); // 비행모델 렌더 TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE ); RS( D3DRS_LIGHTING, TRUE ); RS( D3DRS_AMBIENT, 0 ); m_pd3dDevice->LightEnable( 0, TRUE ); D3DXMatrixTranslation( &m, 1.0f, 0.0f ,0.0f ); D3DXMatrixRotationY( &mR, m_fTime ); D3DXMatrixTranslation( &mT, 1.0f, 1.0f ,0.0f ); m = m * mR * mT * m_mWorld; m_pd3dDevice->SetTransform( D3DTS_WORLD, &m); m_pMesh ->Render( m_pd3dDevice ); //------------------------------------------------- // 셰이더 설정 //------------------------------------------------- m_pEffect->SetTechnique( m_hTechnique ); m_pEffect->Begin( NULL, 0 ); //------------------------------------------------- // 2패스:뭉개기 X //------------------------------------------------- m_pd3dDevice->SetRenderTarget(0, m_pXMapSurf); m_pEffect->Pass( 0 ); RS( D3DRS_ZENABLE, FALSE ); RS( D3DRS_LIGHTING, FALSE ); TSS(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); TSS(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); TSS(1,D3DTSS_COLOROP, D3DTOP_DISABLE); typedef struct {FLOAT p[3];FLOAT tu, tv;} VERTEX; VERTEX Vertex1[4] = { // x y z tu tv {{ 1.0f, -1.0f, 0.1f}, 1, 1,}, {{ -1.0f, -1.0f, 0.1f}, 0, 1,}, {{ -1.0f, 1.0f, 0.1f}, 0, 0,}, {{ 1.0f, 1.0f, 0.1f}, 1, 0,}, }; m_pd3dDevice->SetFVF( D3DFVF_XYZ | D3DFVF_TEX1 ); m_pEffect->SetTexture(m_htSrcMap, m_pOriginalMap); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN , 2, Vertex1, sizeof( VERTEX ) ); //------------------------------------------------- // 2패스:뭉개기 Y //------------------------------------------------- m_pd3dDevice->SetRenderTarget(0, m_pXYMapSurf); m_pEffect->Pass( 1 ); m_pEffect->SetTexture(m_htSrcMap, m_pXMap); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN , 2, Vertex1, sizeof( VERTEX ) ); m_pEffect->End(); } //----------------------------------------------------- // 렌더링타겟 복구 //----------------------------------------------------- m_pd3dDevice->SetRenderTarget(0, pOldBackBuffer); m_pd3dDevice->SetDepthStencilSurface(pOldZBuffer); m_pd3dDevice->SetViewport(&oldViewport); pOldBackBuffer->Release(); pOldZBuffer->Release(); // 버퍼 클리어 m_pd3dDevice->Clear( 0L, NULL , D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER , 0x00404080, 1.0f, 0L ); //----------------------------------------------------- // 그대로 붙인다 //----------------------------------------------------- FLOAT w = (FLOAT)oldViewport.Width; FLOAT h = (FLOAT)oldViewport.Height; TVERTEX Vertex1[4] = { //x y z rhw tu tv { 0, 0, 0.1f, 1.0f, 0+0.5f/MAP_WIDTH, 0+0.5f/MAP_HEIGHT,}, { w, 0, 0.1f, 1.0f, 1+0.5f/MAP_WIDTH, 0+0.5f/MAP_HEIGHT,}, { w, h, 0.1f, 1.0f, 1+0.5f/MAP_WIDTH, 1+0.5f/MAP_HEIGHT,}, { 0, h, 0.1f, 1.0f, 0+0.5f/MAP_WIDTH, 1+0.5f/MAP_HEIGHT,}, }; m_pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 ); m_pd3dDevice->SetTexture(0, m_pOriginalMap); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN , 2, Vertex1, sizeof( TVERTEX ) ); //----------------------------------------------------- // 블러한 것을 붙인다 //----------------------------------------------------- TVERTEX Vertex2[4] = { // x y z rhw tu tv { 0.0f, 0, 0.1f, 1.0f, 0.0f, 0.0f,}, { 0.5f*w, 0, 0.1f, 1.0f, 0.5f, 0.0f,}, { 0.5f*w, h, 0.1f, 1.0f, 0.5f, 1.0f,}, { 0.0f, h, 0.1f, 1.0f, 0.0f, 1.0f,}, }; m_pd3dDevice->SetTexture(0, m_pXYMap); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN , 2, Vertex2, sizeof( TVERTEX ) ); RS( D3DRS_ZENABLE, TRUE ); RS( D3DRS_LIGHTING, TRUE ); RenderText(); // 도움말 출력 #if 1 // 디버그용 텍스처 출력 { m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); m_pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_DISABLE); m_pd3dDevice->SetVertexShader(NULL); m_pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 ); m_pd3dDevice->SetPixelShader(0); float scale = 128.0f; for(DWORD i=0; i<3; i++){ TVERTEX Vertex[4] = { // x y z rhw tu tv { 0,(i+0)*scale,0, 1, 0, 0,}, {scale,(i+0)*scale,0, 1, 1, 0,}, {scale,(i+1)*scale,0, 1, 1, 1,}, { 0,(i+1)*scale,0, 1, 0, 1,}, }; if(0==i) m_pd3dDevice->SetTexture( 0, m_pOriginalMap ); if(1==i) m_pd3dDevice->SetTexture( 0, m_pXMap ); if(2==i) m_pd3dDevice->SetTexture( 0, m_pXYMap ); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, Vertex, sizeof( TVERTEX ) ); } } #endif m_pd3dDevice->EndScene(); // 렌더종료 } return S_OK; }
//------------------------------------------------------------- // Name: Render() // Desc: 화면 렌더 //------------------------------------------------------------- HRESULT CMyD3DApplication::Render() { D3DXMATRIX m, mT, mR, mView, mProj; LPDIRECT3DSURFACE9 pOldBackBuffer, pOldZBuffer; D3DVIEWPORT9 oldViewport; DWORD i; // 뷰포트 D3DVIEWPORT9 viewport = {0,0 // 좌측상단 , MAP_WIDTH // 폭 , MAP_HEIGHT // 높이 , 0.0f,1.0f}; // 전면,후면 //------------------------------------------------- // 렌더링타겟 보존 //------------------------------------------------- m_pd3dDevice->GetRenderTarget(0, &pOldBackBuffer); m_pd3dDevice->GetDepthStencilSurface(&pOldZBuffer); m_pd3dDevice->GetViewport(&oldViewport); //--------------------------------------------------------- // 렌더 //--------------------------------------------------------- if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { const DWORD RENDERING_COUNT = 10;// 렌더회수 for(i=0;i<RENDERING_COUNT;i++){ FLOAT time = m_fLast + (m_fTime-m_fLast)*((FLOAT)i+1)/RENDERING_COUNT; // 렌더링타겟 변경 m_pd3dDevice->SetRenderTarget(0, m_pSurf); m_pd3dDevice->SetDepthStencilSurface(m_pZ); m_pd3dDevice->SetViewport(&viewport); DWORD alpha = 255/(i+1); m_pd3dDevice->Clear(0L, NULL , D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , D3DCOLOR_RGBA(0,0,0,alpha), 1.0f, 0L); RS(D3DRS_COLORWRITEENABLE, 0x7); //------------------------------------------------- // 일반장면 렌더 //------------------------------------------------- m_pd3dDevice->SetTransform( D3DTS_WORLD, &m_mWorld); m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_mView ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &m_mProj ); RS( D3DRS_ZENABLE, TRUE ); RS( D3DRS_LIGHTING, TRUE ); TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); m_pMeshBg->Render( m_pd3dDevice ); // 비행모델 렌더 TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE ); RS( D3DRS_LIGHTING, TRUE ); RS( D3DRS_AMBIENT, 0 ); m_pd3dDevice->LightEnable( 0, TRUE ); D3DXMatrixTranslation( &m, 1.0f, 0.0f ,0.0f ); D3DXMatrixRotationY( &mR, time ); D3DXMatrixTranslation( &mT, 1.0f, 1.0f ,0.0f ); m = m * mR * mT * m_mWorld; m_pd3dDevice->SetTransform( D3DTS_WORLD, &m); m_pMesh ->Render( m_pd3dDevice ); //------------------------------------------------- // 렌더링타겟 복구 //------------------------------------------------- m_pd3dDevice->SetRenderTarget(0, pOldBackBuffer); m_pd3dDevice->SetDepthStencilSurface(NULL); m_pd3dDevice->SetViewport(&oldViewport); RS( D3DRS_ZENABLE, FALSE ); RS( D3DRS_LIGHTING, FALSE ); RS( D3DRS_COLORWRITEENABLE, 0xf); TSS(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); TSS(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); RS( D3DRS_ALPHABLENDENABLE, TRUE); RS( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); RS( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); //----------------------------------------------------- // 그대로 붙인다 //----------------------------------------------------- FLOAT w = (FLOAT)oldViewport.Width; FLOAT h = (FLOAT)oldViewport.Width; TVERTEX Vertex1[4] = { //x y z rhw tu tv { 0, 0, 0.1f, 1.0f, 0, 0,}, { w, 0, 0.1f, 1.0f, 1, 0,}, { w, h, 0.1f, 1.0f, 1, 1,}, { 0, h, 0.1f, 1.0f, 0, 1,}, }; m_pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 ); m_pd3dDevice->SetTexture(0, m_pTex); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN , 2, Vertex1, sizeof( TVERTEX ) ); RS(D3DRS_ALPHABLENDENABLE, FALSE); } m_pd3dDevice->SetDepthStencilSurface(pOldZBuffer); // 현재시각 보존 m_fLast = m_fTime; RenderText(); // 도움말 출력 #if 1 // 디버그용 텍스처 출력 { m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); m_pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_DISABLE); m_pd3dDevice->SetVertexShader(NULL); m_pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 ); m_pd3dDevice->SetPixelShader(0); float scale = 128.0f; for(DWORD i=0; i<1; i++){ TVERTEX Vertex[4] = { // x y z rhw tu tv { 0,(i+0)*scale,0, 1, 0, 0,}, {scale,(i+0)*scale,0, 1, 1, 0,}, {scale,(i+1)*scale,0, 1, 1, 1,}, { 0,(i+1)*scale,0, 1, 0, 1,}, }; if(0==i) m_pd3dDevice->SetTexture( 0, m_pTex ); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, Vertex, sizeof( TVERTEX ) ); } } #endif m_pd3dDevice->EndScene(); // 렌더종료 } pOldBackBuffer->Release(); pOldZBuffer->Release(); Sleep(100); return S_OK; }
//------------------------------------------------------------- // Name: RestoreDeviceObjects() // Desc: 화면크기가 변했을때 호출됨 // 확보한 메모리는 InvalidateDeviceObjects()에서 해제 //------------------------------------------------------------- HRESULT CMyD3DApplication::RestoreDeviceObjects() { LPDIRECT3DSURFACE9 pOldBackBuffer, pOldZBuffer; m_pd3dDevice->GetRenderTarget(0, &pOldBackBuffer); m_pd3dDevice->GetDepthStencilSurface(&pOldZBuffer); // 메시 m_pMesh ->RestoreDeviceObjects( m_pd3dDevice ); m_pMeshBg->RestoreDeviceObjects( m_pd3dDevice ); // 재질설정 D3DMATERIAL9 mtrl; D3DUtil_InitMaterial( mtrl, 1.0f, 0.0f, 0.0f ); m_pd3dDevice->SetMaterial( &mtrl ); // 렌더링 상태설정 RS( D3DRS_DITHERENABLE, FALSE ); RS( D3DRS_SPECULARENABLE, FALSE ); RS( D3DRS_ZENABLE, TRUE ); RS( D3DRS_AMBIENT, 0x000F0F0F ); TSS( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); TSS( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); TSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); SAMP( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); SAMP( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); SAMP( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); SAMP( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); // 월드행렬 D3DXMATRIX matIdentity; D3DXMatrixIdentity( &m_mWorld ); // 뷰행렬 D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -5.0f ); D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); D3DXMatrixLookAtLH( &m_mView, &vFromPt, &vLookatPt, &vUpVec ); // 투영행렬 FLOAT fAspect = ((FLOAT)m_d3dsdBackBuffer.Width) / m_d3dsdBackBuffer.Height; D3DXMatrixPerspectiveFovLH( &m_mProj, D3DX_PI/4, fAspect, 1.0f, 100.0f ); // 폰트 m_pFont->RestoreDeviceObjects(); // 렌더링타겟 생성 if (FAILED(m_pd3dDevice->CreateDepthStencilSurface( MAP_WIDTH, MAP_HEIGHT, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, TRUE, &m_pZ, NULL))) return E_FAIL; m_pd3dDevice->SetDepthStencilSurface(NULL); if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ){ if (FAILED(m_pd3dDevice->CreateTexture( MAP_WIDTH, MAP_HEIGHT, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pTex, NULL))) return E_FAIL; if (FAILED(m_pTex->GetSurfaceLevel(0, &m_pSurf))) return E_FAIL; // 표면초기화 m_pd3dDevice->SetRenderTarget(0, m_pSurf); m_pd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET , 0xffffffff, 1.0f, 0L); m_pd3dDevice->EndScene(); } //----------------------------------------------------- // 렌더링타겟 복구 //----------------------------------------------------- m_pd3dDevice->SetRenderTarget(0, pOldBackBuffer); m_pd3dDevice->SetDepthStencilSurface(pOldZBuffer); pOldBackBuffer->Release(); pOldZBuffer->Release(); return S_OK; }
//------------------------------------------------------------- // Name: RestoreDeviceObjects() // Desc: ȸéÅ©±â°¡ º¯ÇßÀ»¶§ È£ÃâµÊ // È®º¸ÇÑ ¸Þ¸ð¸®´Â InvalidateDeviceObjects()¿¡¼ ÇØÁ¦ //------------------------------------------------------------- HRESULT CMyD3DApplication::RestoreDeviceObjects() { // ¸Þ½Ã m_pMesh ->RestoreDeviceObjects( m_pd3dDevice ); m_pMeshBg->RestoreDeviceObjects( m_pd3dDevice ); // ·»´õ¸µ »óż³Á¤ RS( D3DRS_DITHERENABLE, FALSE ); RS( D3DRS_SPECULARENABLE, FALSE ); RS( D3DRS_ZENABLE, TRUE ); RS( D3DRS_AMBIENT, 0x000F0F0F ); TSS( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); TSS( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); TSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); TSS( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE ); SAMP( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); SAMP( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); SAMP( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); SAMP( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); // ¿ùµåÇà·Ä D3DXMATRIX matIdentity; D3DXMatrixIdentity( &m_mWorld ); // ºäÇà·Ä D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.2f, -5.0f ); D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.5f, 0.0f ); D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); D3DXMatrixLookAtLH( &m_mView, &vFromPt, &vLookatPt, &vUpVec ); // Åõ¿µÇà·Ä FLOAT fAspect = ((FLOAT)m_d3dsdBackBuffer.Width) / m_d3dsdBackBuffer.Height; D3DXMatrixPerspectiveFovLH( &m_mProj, D3DX_PI/4, fAspect, 1.0f, 7.0f ); // ÆùÆ® m_pFont->RestoreDeviceObjects(); // ·»´õ¸µÅ¸°Ù »ý¼º // ±íÀ̹öÆÛ if (FAILED(m_pd3dDevice->CreateDepthStencilSurface( MAP_WIDTH, MAP_HEIGHT, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, TRUE, &m_pMapZ, NULL))) return E_FAIL; // »öÁ¤º¸ if (FAILED(m_pd3dDevice->CreateTexture( MAP_WIDTH, MAP_HEIGHT, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pOriginalTex, NULL))) return E_FAIL; if (FAILED(m_pOriginalTex->GetSurfaceLevel(0, &m_pOriginalSurf))) return E_FAIL; // ¹ý¼±¸Ê if (FAILED(m_pd3dDevice->CreateTexture( MAP_WIDTH, MAP_HEIGHT, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pNormalTex, NULL))) return E_FAIL; if (FAILED(m_pNormalTex->GetSurfaceLevel(0, &m_pNormalSurf))) return E_FAIL; m_pEffect->OnResetDevice(); return S_OK; }
//------------------------------------------------------------- // Name: Render() // Desc: 화면 렌더 //------------------------------------------------------------- HRESULT CMyD3DApplication::Render() { D3DXMATRIX m, mT, mR, mView, mProj; //--------------------------------------------------------- // 렌더 //--------------------------------------------------------- if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { // 클리어 m_pd3dDevice->Clear(0L, NULL , D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , 0xffffffff, 1.0f, 0L); if( m_pEffect != NULL ) { //------------------------------------------------- // 셰이더 설정 //------------------------------------------------- m_pEffect->SetTechnique( m_hTechnique ); m_pEffect->Begin( NULL, 0 ); m_pEffect->Pass( 0 ); //------------------------------------------------- // 필터링 //------------------------------------------------- RS( D3DRS_ZENABLE, FALSE ); RS( D3DRS_LIGHTING, FALSE ); TSS(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); TSS(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); TSS(1,D3DTSS_COLOROP, D3DTOP_DISABLE); TVERTEX Vertex1[4] = { // x y z tu tv {-1.0f, 1.0f, 0.1f, 0, 0,}, { 1.0f, 1.0f, 0.1f, 1, 0,}, { 1.0f,-1.0f, 0.1f, 1, 1,}, {-1.0f,-1.0f, 0.1f, 0, 1,}, }; m_pd3dDevice->SetVertexDeclaration( m_pDecl ); m_pEffect->SetTexture(m_htSrcMap, m_pTex); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN , 2, Vertex1, sizeof( TVERTEX ) ); m_pEffect->End(); } RS( D3DRS_ZENABLE, TRUE ); RS( D3DRS_LIGHTING, TRUE ); RenderText(); // 도움말 출력 #if 1 // 디버그용 텍스처 출력 { m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); m_pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_DISABLE); m_pd3dDevice->SetVertexShader(NULL); m_pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 ); m_pd3dDevice->SetPixelShader(0); float scale = 128.0f; for(DWORD i=0; i<1; i++){ TVERTEX Vertex[4] = { // x y z rhw tu tv { 0,(i+0)*scale,0, 1, 0, 0,}, {scale,(i+0)*scale,0, 1, 1, 0,}, {scale,(i+1)*scale,0, 1, 1, 1,}, { 0,(i+1)*scale,0, 1, 0, 1,}, }; if(0==i) m_pd3dDevice->SetTexture( 0, m_pTex ); m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, Vertex, sizeof( TVERTEX ) ); } } #endif m_pd3dDevice->EndScene(); // 렌더종료 } return S_OK; }
//------------------------------------------------------------- // Name: RestoreDeviceObjects() // Desc: ȭ��ũ�Ⱑ �������� ȣ��� // Ȯ���� �� InvalidateDeviceObjects()���� ���� //------------------------------------------------------------- HRESULT CMyD3DApplication::RestoreDeviceObjects() { // ���ڸ� ���� if (FAILED(m_pd3dDevice->CreateTexture( SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pShadowTex, NULL))) return E_FAIL; if (FAILED(m_pShadowTex->GetSurfaceLevel(0, &m_pShadowSurf))) return E_FAIL; if (FAILED(m_pd3dDevice->CreateDepthStencilSurface( SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, TRUE, &m_pZ, NULL))) return E_FAIL; // �� m_pMesh ->RestoreDeviceObjects( m_pd3dDevice ); m_pMeshBg->RestoreDeviceObjects( m_pd3dDevice ); // �������� D3DMATERIAL9 mtrl; D3DUtil_InitMaterial( mtrl, 1.0f, 0.0f, 0.0f ); m_pd3dDevice->SetMaterial( &mtrl ); // �����ũ�� #define RS m_pd3dDevice->SetRenderState #define TSS m_pd3dDevice->SetTextureStageState #define SAMP m_pd3dDevice->SetSamplerState // ������ ���¼��� RS( D3DRS_DITHERENABLE, FALSE ); RS( D3DRS_SPECULARENABLE, FALSE ); RS( D3DRS_ZENABLE, TRUE ); RS( D3DRS_AMBIENT, 0x000F0F0F ); TSS( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); TSS( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); TSS( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); TSS( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); TSS( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); SAMP( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); SAMP( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); // ������� D3DXMATRIX matIdentity; D3DXMatrixIdentity( &m_mWorld ); // ����� D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -5.0f ); D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); D3DXMatrixLookAtLH( &m_mView, &vFromPt, &vLookatPt, &vUpVec ); // ������� FLOAT fAspect = ((FLOAT)m_d3dsdBackBuffer.Width) / m_d3dsdBackBuffer.Height; D3DXMatrixPerspectiveFovLH( &m_mProj, D3DX_PI/4, fAspect, 1.0f, 100.0f ); // ��Ʈ m_pFont->RestoreDeviceObjects(); m_pEffect->OnResetDevice(); return S_OK; }