// Does a lot more that just a standard begin scene, this restores the surfaces, // erases the backbuffer, points the camara etc. HRESULT Direct3D::BeginScene(D3DVECTOR At, // Viewer position D3DVECTOR To) // Look to position { // Make sure the device pointer is valid if(0 == D3DDevice) return(E_FAIL); // Restore any lost surfaces if(DDERR_SURFACELOST == PrimarySurface->IsLost()) PrimarySurface->Restore(); if(DDERR_SURFACELOST == BackBuffer->IsLost()) BackBuffer->Restore(); if(DDERR_SURFACELOST == ZBuffer->IsLost()) ZBuffer->Restore(); D3DTextr_RestoreAllTextures(D3DDevice); static HRESULT Return; // Set up a view matrix static D3DMATRIX VM; D3DUtil_SetViewMatrix(VM, At, To, D3DVECTOR(0, 1, 0)); // Apply the view matrix Return = D3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &VM); if(FAILED(Return)) return Return; // Clear the viewport if freeform is off, or just clear the ZBuffer // and draw a copy of the GDI surface if it is on if(IsFreeForm) { // clear the z-buffer Return = D3DDevice->Clear(0, 0, D3DCLEAR_ZBUFFER, 0, 1.0f, 0); if(FAILED(Return)) return Return; // Copy the screenshot onto the backbuffer HDC hdc, xdc; BackBuffer->GetDC(&hdc); GDIScreenShot->GetDC(&xdc); StretchBlt(hdc, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), xdc, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SRCCOPY); BackBuffer->ReleaseDC(hdc); GDIScreenShot->ReleaseDC(xdc); } // end if else { // Just clear the viewport Return = D3DDevice->Clear(0, 0, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, FogColor, 1.0f, 0); if(FAILED(Return)) return Return; } // end else // Start the scene render Return = D3DDevice->BeginScene(); if(FAILED(Return)) return Return; // Return success return(D3D_OK); } // end Direct3D::BeginScene
VOID CSelectSrv::Draw3DBorder(RECT rcWnd,COLORREF dwColor,INT nAlpha) { if ( g_xMainWnd.Get3DDevice() ) { D3DVECTOR vTrans; D3DMATRIX matTrans; D3DMATRIX matScale; D3DMATRIX matWorld; D3DMATRIX matView; D3DMATRIX matProj; D3DMATRIX matWorldOriginal; D3DMATERIAL7 mtrl; if( SUCCEEDED(g_xMainWnd.Get3DDevice()->BeginScene())) { g_xMainWnd.Get3DDevice()->GetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal); ZeroMemory(&matView, sizeof(D3DMATRIX)); D3DVECTOR vEyePt = D3DVECTOR(0, 0, -(float)((g_xMainWnd.m_rcWindow.bottom - g_xMainWnd.m_rcWindow.top)/2)); D3DVECTOR vLookatPt = D3DVECTOR(0, 0, 0); D3DVECTOR vUpVec = D3DVECTOR(0, 1, 0); D3DUtil_SetViewMatrix(matView, vEyePt, vLookatPt, vUpVec); D3DUtil_SetProjectionMatrix(matProj, g_PI/2, float(240.0f/320.0f), -1.0f, 1.0f); g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_VIEW, &matView); g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &matProj); vTrans.x = (FLOAT)rcWnd.left - 320.0f + (rcWnd.right - rcWnd.left)/2; vTrans.y = (FLOAT)-rcWnd.top + 240.0f - (rcWnd.bottom - rcWnd.top )/2; vTrans.z = 0; D3DUtil_SetTranslateMatrix(matTrans, vTrans); D3DUtil_SetScaleMatrix(matScale, (FLOAT)(rcWnd.right - rcWnd.left), (FLOAT)(rcWnd.bottom - rcWnd.top), 0.0f); D3DMath_MatrixMultiply(matWorld, matScale, matTrans); g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorld); // 임시 D3DUtil_InitMaterial(mtrl, (FLOAT)GetRValue(dwColor)/255.0f, (FLOAT)GetGValue(dwColor)/255.0f, (FLOAT)GetBValue(dwColor)/255.0f); mtrl.diffuse.a = nAlpha/255.0f; // alpha value g_xMainWnd.Get3DDevice()->SetMaterial(&mtrl); g_xMainWnd.Get3DDevice()->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE ); g_xMainWnd.Get3DDevice()->SetRenderState( D3DRENDERSTATE_COLORKEYENABLE, TRUE); g_xMainWnd.Get3DDevice()->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); g_xMainWnd.Get3DDevice()->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); g_xMainWnd.Get3DDevice()->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE); g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA); g_xMainWnd.Get3DDevice()->SetTexture(0, NULL); g_xMainWnd.Get3DDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX, m_avBillBoard, 4, NULL); g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE); g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, FALSE); g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND , D3DBLEND_ONE); g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO); g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal); g_xMainWnd.Get3DDevice()->EndScene(); } } }