0001:
0002:
0003:
0004:
0005:
0006: #define STRICT
0007: #include <windows.h>
0008: #include <commctrl.h>
0009: #include <commdlg.h>
0010: #include <basetsd.h>
0011: #include <math.h>
0012: #include <stdio.h>
0013: #include <d3dx9.h>
0014: #include <dxerr9.h>
0015: #include <tchar.h>
0016: #include "DXUtil.h"
0017: #include "D3DEnumeration.h"
0018: #include "D3DSettings.h"
0019: #include "D3DApp.h"
0020: #include "D3DFont.h"
0021: #include "D3DFile.h"
0022: #include "D3DUtil.h"
0023: #include "resource.h"
0024: #include "main.h"
0025:
0026: #define MAP_WIDTH 512
0027: #define MAP_HEIGHT 512
0028:
0029:
0030:
0031: #define RS m_pd3dDevice->SetRenderState
0032: #define TSS m_pd3dDevice->SetTextureStageState
0033: #define SAMP m_pd3dDevice->SetSamplerState
0034:
0035:
0036:
0037:
0038:
0039: typedef struct {
0040: FLOAT p[4];
0041: FLOAT tu, tv;
0042: } TVERTEX;
0043:
0044:
0045:
0046:
0047: CMyD3DApplication* g_pApp = NULL;
0048: HINSTANCE g_hInst = NULL;
0049:
0050:
0051:
0052:
0053:
0054:
0055: INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
0056: {
0057: CMyD3DApplication d3dApp;
0058:
0059: g_pApp = &d3dApp;
0060: g_hInst = hInst;
0061:
0062: InitCommonControls();
0063: if( FAILED( d3dApp.Create( hInst ) ) )
0064: return 0;
0065:
0066: return d3dApp.Run();
0067: }
0068:
0069:
0070:
0071:
0072:
0073:
0074:
0075:
0076: CMyD3DApplication::CMyD3DApplication()
0077: {
0078: m_dispersion_sq = 5.0f;
0079:
0080: m_pMesh = new CD3DMesh();
0081: m_pMeshBg = new CD3DMesh();
0082:
0083: m_pMapZ = NULL;
0084: m_pOriginalMap = NULL;
0085: m_pOriginalMapSurf = NULL;
0086: m_pXMap = NULL;
0087: m_pXMapSurf = NULL;
0088: m_pXYMap = NULL;
0089: m_pXYMapSurf = NULL;
0090:
0091: m_pEffect = NULL;
0092: m_hTechnique = NULL;
0093: m_hafWeight = NULL;
0094: m_htSrcMap = NULL;
0095:
0096: m_fWorldRotX = -0.41271535f;
0097: m_fWorldRotY = 0.0f;
0098: m_fViewZoom = 5.0f;
0099:
0100: m_dwCreationWidth = 512;
0101: m_dwCreationHeight = 512;
0102: m_strWindowTitle = TEXT( "main" );
0103: m_d3dEnumeration.AppUsesDepthBuffer = TRUE;
0104: m_bStartFullscreen = false;
0105: m_bShowCursorWhenFullscreen = false;
0106:
0107: m_pFont = new CD3DFont( _T("Arial"), 12, D3DFONT_BOLD );
0108: m_bLoadingApp = TRUE;
0109:
0110: ZeroMemory( &m_UserInput, sizeof(m_UserInput) );
0111: }
0112:
0113:
0114:
0115:
0116:
0117:
0118:
0119:
0120: CMyD3DApplication::~CMyD3DApplication()
0121: {
0122: }
0123:
0124:
0125:
0126:
0127:
0128:
0129:
0130:
0131:
0132:
0133: HRESULT CMyD3DApplication::OneTimeSceneInit()
0134: {
0135:
0136: SendMessage( m_hWnd, WM_PAINT, 0, 0 );
0137:
0138: m_bLoadingApp = FALSE;
0139:
0140: return S_OK;
0141: }
0142:
0143:
0144:
0145:
0146:
0147:
0148:
0149:
0150: HRESULT CMyD3DApplication::ConfirmDevice( D3DCAPS9* pCaps,
0151: DWORD dwBehavior, D3DFORMAT Format )
0152: {
0153: UNREFERENCED_PARAMETER( Format );
0154: UNREFERENCED_PARAMETER( dwBehavior );
0155: UNREFERENCED_PARAMETER( pCaps );
0156:
0157:
0158:
0159: if( pCaps->PixelShaderVersion < D3DPS_VERSION(2,0) )
0160: return E_FAIL;
0161:
0162:
0163: if( pCaps->VertexShaderVersion < D3DVS_VERSION(1,1)
0164: && 0==(dwBehavior & D3DCREATE_SOFTWARE_VERTEXPROCESSING) )
0165: return E_FAIL;
0166:
0167: return S_OK;
0168: }
0169:
0170:
0171:
0172:
0173:
0174:
0175:
0176:
0177: VOID CMyD3DApplication::UpdateWeight( FLOAT dispersion )
0178: {
0179: DWORD i;
0180:
0181: FLOAT total=0;
0182: for( i=0; i<WEIGHT_MUN; i++ ){
0183: m_tbl[i] = expf(-0.5f*(FLOAT)(i*i)/dispersion);
0184: if(0==i){
0185: total += m_tbl[i];
0186: }else{
0187:
0188: total += 2.0f*m_tbl[i];
0189: }
0190: }
0191:
0192: for( i=0; i<WEIGHT_MUN; i++ ) m_tbl[i] /= total;
0193:
0194: if(m_pEffect) m_pEffect->SetFloatArray(m_hafWeight
0195: , m_tbl, WEIGHT_MUN);
0196:
0197: }
0198:
0199:
0200:
0201:
0202:
0203:
0204:
0205:
0206:
0207:
0208:
0209: HRESULT CMyD3DApplication::InitDeviceObjects()
0210: {
0211: HRESULT hr;
0212:
0213:
0214: if(FAILED(hr=m_pMesh ->Create( m_pd3dDevice, _T("ufo.x"))))
0215: return DXTRACE_ERR( "LoadCar", hr );
0216:
0217: if(FAILED(hr=m_pMeshBg->Create( m_pd3dDevice, _T("map.x"))))
0218: return DXTRACE_ERR( "Load BG", hr );
0219:
0220:
0221: LPD3DXBUFFER pErr;
0222: if( FAILED( hr = D3DXCreateEffectFromFile(
0223: m_pd3dDevice, "hlsl.fx", NULL, NULL,
0224: D3DXSHADER_DEBUG , NULL, &m_pEffect, &pErr ))){
0225: MessageBox( NULL, (LPCTSTR)pErr->GetBufferPointer()
0226: , "ERROR", MB_OK);
0227: return DXTRACE_ERR( "CreateEffectFromFile", hr );
0228: }
0229: m_hTechnique = m_pEffect->GetTechniqueByName( "TShader" );
0230: m_hafWeight = m_pEffect->GetParameterByName( NULL, "weight" );
0231: m_htSrcMap = m_pEffect->GetParameterByName( NULL, "SrcMap" );
0232: hr = m_pEffect->SetFloat("MAP_WIDTH", MAP_WIDTH);
0233: hr = m_pEffect->SetFloat("MAP_HEIGHT", MAP_HEIGHT);
0234:
0235:
0236: this->UpdateWeight(m_dispersion_sq*m_dispersion_sq);
0237:
0238:
0239: m_pFont->InitDeviceObjects( m_pd3dDevice );
0240:
0241: return S_OK;
0242: }
0243:
0244:
0245:
0246:
0247:
0248:
0249: HRESULT CMyD3DApplication::RestoreDeviceObjects()
0250: {
0251:
0252: m_pMesh ->RestoreDeviceObjects( m_pd3dDevice );
0253: m_pMeshBg->RestoreDeviceObjects( m_pd3dDevice );
0254:
0255:
0256: D3DMATERIAL9 mtrl;
0257: D3DUtil_InitMaterial( mtrl, 1.0f, 0.0f, 0.0f );
0258: m_pd3dDevice->SetMaterial( &mtrl );
0259:
0260:
0261:
0262: RS( D3DRS_DITHERENABLE, FALSE );
0263: RS( D3DRS_SPECULARENABLE, FALSE );
0264: RS( D3DRS_ZENABLE, TRUE );
0265: RS( D3DRS_AMBIENT, 0x000F0F0F );
0266:
0267: TSS( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
0268: TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
0269: TSS( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
0270: TSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
0271: TSS( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
0272: SAMP( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
0273: SAMP( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
0274: SAMP( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
0275: SAMP( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );
0276:
0277:
0278: D3DXMATRIX matIdentity;
0279: D3DXMatrixIdentity( &m_mWorld );
0280:
0281:
0282: D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -5.0f );
0283: D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
0284: D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
0285: D3DXMatrixLookAtLH( &m_mView, &vFromPt, &vLookatPt, &vUpVec );
0286:
0287:
0288: FLOAT fAspect = ((FLOAT)m_d3dsdBackBuffer.Width) / m_d3dsdBackBuffer.Height;
0289: D3DXMatrixPerspectiveFovLH( &m_mProj, D3DX_PI/4, fAspect, 1.0f, 100.0f );
0290:
0291:
0292: m_pFont->RestoreDeviceObjects();
0293:
0294:
0295: if (FAILED(m_pd3dDevice->CreateDepthStencilSurface(MAP_WIDTH, MAP_HEIGHT,
0296: D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, TRUE, &m_pMapZ, NULL)))
0297: return E_FAIL;
0298: if (FAILED(m_pd3dDevice->CreateTexture(MAP_WIDTH, MAP_HEIGHT, 1,
0299: D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pOriginalMap, NULL)))
0300: return E_FAIL;
0301: if (FAILED(m_pOriginalMap->GetSurfaceLevel(0, &m_pOriginalMapSurf)))
0302: return E_FAIL;
0303:
0304: if (FAILED(m_pd3dDevice->CreateTexture(MAP_WIDTH, MAP_HEIGHT, 1,
0305: D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pXMap, NULL)))
0306: return E_FAIL;
0307: if (FAILED(m_pXMap->GetSurfaceLevel(0, &m_pXMapSurf)))
0308: return E_FAIL;
0309:
0310: if (FAILED(m_pd3dDevice->CreateTexture(MAP_WIDTH, MAP_HEIGHT, 1,
0311: D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pXYMap, NULL)))
0312: return E_FAIL;
0313: if (FAILED(m_pXYMap->GetSurfaceLevel(0, &m_pXYMapSurf)))
0314: return E_FAIL;
0315:
0316: m_pEffect->OnResetDevice();
0317:
0318: return S_OK;
0319: }
0320:
0321:
0322:
0323:
0324:
0325:
0326:
0327:
0328: HRESULT CMyD3DApplication::FrameMove()
0329: {
0330:
0331: UpdateInput( &m_UserInput );
0332:
0333:
0334:
0335:
0336:
0337: D3DXMATRIX matRotY;
0338: D3DXMATRIX matRotX;
0339:
0340: if( m_UserInput.bRotateLeft && !m_UserInput.bRotateRight )
0341: m_fWorldRotY += m_fElapsedTime;
0342: else
0343: if( m_UserInput.bRotateRight && !m_UserInput.bRotateLeft )
0344: m_fWorldRotY -= m_fElapsedTime;
0345:
0346: if( m_UserInput.bRotateUp && !m_UserInput.bRotateDown )
0347: m_fWorldRotX += m_fElapsedTime;
0348: else
0349: if( m_UserInput.bRotateDown && !m_UserInput.bRotateUp )
0350: m_fWorldRotX -= m_fElapsedTime;
0351:
0352: D3DXMatrixRotationX( &matRotX, m_fWorldRotX );
0353: D3DXMatrixRotationY( &matRotY, m_fWorldRotY );
0354:
0355: D3DXMatrixMultiply( &m_mWorld, &matRotY, &matRotX );
0356:
0357:
0358:
0359:
0360:
0361: if( m_UserInput.bZoomIn && !m_UserInput.bZoomOut )
0362: m_fViewZoom += m_fElapsedTime;
0363: else if( m_UserInput.bZoomOut && !m_UserInput.bZoomIn )
0364: m_fViewZoom -= m_fElapsedTime;
0365:
0366: D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -m_fViewZoom );
0367: D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
0368: D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
0369: D3DXMatrixLookAtLH( &m_mView, &vFromPt, &vLookatPt, &vUpVec );
0370:
0371:
0372: if( m_UserInput.bDispersionUp && !m_UserInput.bDispersionDown ){
0373: m_dispersion_sq += m_fElapsedTime;
0374: this->UpdateWeight(m_dispersion_sq*m_dispersion_sq);
0375: } else
0376: if( m_UserInput.bDispersionDown && !m_UserInput.bDispersionUp ){
0377: m_dispersion_sq -= m_fElapsedTime;
0378: this->UpdateWeight(m_dispersion_sq*m_dispersion_sq);
0379: }
0380:
0381:
0382: return S_OK;
0383: }
0384:
0385:
0386:
0387:
0388: void CMyD3DApplication::UpdateInput( UserInput* pUserInput )
0389: {
0390: pUserInput->bRotateUp = ( m_bActive && (GetAsyncKeyState( VK_UP ) & 0x8000) == 0x8000 );
0391: pUserInput->bRotateDown = ( m_bActive && (GetAsyncKeyState( VK_DOWN ) & 0x8000) == 0x8000 );
0392: pUserInput->bRotateLeft = ( m_bActive && (GetAsyncKeyState( VK_LEFT ) & 0x8000) == 0x8000 );
0393: pUserInput->bRotateRight = ( m_bActive && (GetAsyncKeyState( VK_RIGHT ) & 0x8000) == 0x8000 );
0394:
0395: pUserInput->bZoomIn = ( m_bActive && (GetAsyncKeyState( 'Z' ) & 0x8000) == 0x8000 );
0396: pUserInput->bZoomOut = ( m_bActive && (GetAsyncKeyState( 'X' ) & 0x8000) == 0x8000 );
0397:
0398: pUserInput->bDispersionUp = ( m_bActive && (GetAsyncKeyState( VK_PRIOR) & 0x8000) == 0x8000 );
0399: pUserInput->bDispersionDown = ( m_bActive && (GetAsyncKeyState( VK_NEXT ) & 0x8000) == 0x8000 );
0400: }
0401:
0402:
0403:
0404:
0405:
0406:
0407: HRESULT CMyD3DApplication::Render()
0408: {
0409: D3DXMATRIX m, mT, mR, mView, mProj;
0410: LPDIRECT3DSURFACE9 pOldBackBuffer, pOldZBuffer;
0411: D3DVIEWPORT9 oldViewport;
0412:
0413:
0414:
0415:
0416: if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
0417: {
0418:
0419:
0420:
0421: m_pd3dDevice->GetRenderTarget(0, &pOldBackBuffer);
0422: m_pd3dDevice->GetDepthStencilSurface(&pOldZBuffer);
0423: m_pd3dDevice->GetViewport(&oldViewport);
0424:
0425: if( m_pEffect != NULL )
0426: {
0427:
0428:
0429:
0430: m_pd3dDevice->SetRenderTarget(0, m_pOriginalMapSurf);
0431: m_pd3dDevice->SetDepthStencilSurface(m_pMapZ);
0432:
0433: D3DVIEWPORT9 viewport = {0,0
0434: , MAP_WIDTH
0435: , MAP_HEIGHT
0436: , 0.0f,1.0f};
0437: m_pd3dDevice->SetViewport(&viewport);
0438:
0439:
0440: m_pd3dDevice->Clear(0L, NULL
0441: , D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER
0442: , 0xffffffff, 1.0f, 0L);
0443:
0444:
0445:
0446:
0447: m_pd3dDevice->SetTransform( D3DTS_WORLD, &m_mWorld);
0448: m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_mView );
0449: m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &m_mProj );
0450:
0451: TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
0452: TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
0453: m_pMeshBg->Render( m_pd3dDevice );
0454:
0455:
0456: TSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
0457: TSS( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
0458: RS( D3DRS_LIGHTING, TRUE );
0459: RS( D3DRS_AMBIENT, 0 );
0460: m_pd3dDevice->LightEnable( 0, TRUE );
0461: D3DXMatrixTranslation( &m, 1.0f, 0.0f ,0.0f );
0462: D3DXMatrixRotationY( &mR, m_fTime );
0463: D3DXMatrixTranslation( &mT, 1.0f, 1.0f ,0.0f );
0464: m = m * mR * mT * m_mWorld;
0465: m_pd3dDevice->SetTransform( D3DTS_WORLD, &m);
0466: m_pMesh ->Render( m_pd3dDevice );
0467:
0468:
0469:
0470:
0471: m_pEffect->SetTechnique( m_hTechnique );
0472: m_pEffect->Begin( NULL, 0 );
0473:
0474:
0475:
0476:
0477: m_pd3dDevice->SetRenderTarget(0, m_pXMapSurf);
0478: m_pEffect->Pass( 0 );
0479:
0480: RS( D3DRS_ZENABLE, FALSE );
0481: RS( D3DRS_LIGHTING, FALSE );
0482: TSS(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1);
0483: TSS(0,D3DTSS_COLORARG1, D3DTA_TEXTURE);
0484: TSS(1,D3DTSS_COLOROP, D3DTOP_DISABLE);
0485:
0486: TVERTEX Vertex1[4] = {
0487:
0488: { 0.0f, 0.0f, 0.1f, 1.0f, 0, 0,},
0489: {MAP_WIDTH, 0.0f, 0.1f, 1.0f, 1, 0,},
0490: {MAP_WIDTH, MAP_HEIGHT, 0.1f, 1.0f, 1, 1,},
0491: { 0.0f, MAP_HEIGHT, 0.1f, 1.0f, 0, 1,},
0492: };
0493: m_pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 );
0494: m_pEffect->SetTexture(m_htSrcMap, m_pOriginalMap);
0495: m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN
0496: , 2, Vertex1, sizeof( TVERTEX ) );
0497:
0498:
0499:
0500:
0501: m_pd3dDevice->SetRenderTarget(0, m_pXYMapSurf);
0502: m_pEffect->Pass( 1 );
0503:
0504: m_pEffect->SetTexture(m_htSrcMap, m_pXMap);
0505: m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN
0506: , 2, Vertex1, sizeof( TVERTEX ) );
0507:
0508: m_pEffect->End();
0509: }
0510:
0511:
0512:
0513:
0514: m_pd3dDevice->SetRenderTarget(0, pOldBackBuffer);
0515: m_pd3dDevice->SetDepthStencilSurface(pOldZBuffer);
0516: m_pd3dDevice->SetViewport(&oldViewport);
0517: pOldBackBuffer->Release();
0518: pOldZBuffer->Release();
0519:
0520:
0521: m_pd3dDevice->Clear( 0L, NULL
0522: , D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER
0523: , 0x00404080, 1.0f, 0L );
0524:
0525:
0526:
0527:
0528: FLOAT w = (FLOAT)oldViewport.Width;
0529: FLOAT h = (FLOAT)oldViewport.Height;
0530: TVERTEX Vertex1[4] = {
0531:
0532: { 0, 0, 0.1f, 1.0f, 0, 0,},
0533: { w, 0, 0.1f, 1.0f, 1, 0,},
0534: { w, h, 0.1f, 1.0f, 1, 1,},
0535: { 0, h, 0.1f, 1.0f, 0, 1,},
0536: };
0537: m_pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 );
0538: m_pd3dDevice->SetTexture(0, m_pOriginalMap);
0539: m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN
0540: , 2, Vertex1, sizeof( TVERTEX ) );
0541:
0542:
0543:
0544:
0545:
0546: TVERTEX Vertex2[4] = {
0547:
0548: { 0.0f, 0, 0.1f, 1.0f, 0.0f, 0.0f,},
0549: { 0.5f*w, 0, 0.1f, 1.0f, 0.5f, 0.0f,},
0550: { 0.5f*w, h, 0.1f, 1.0f, 0.5f, 1.0f,},
0551: { 0.0f, h, 0.1f, 1.0f, 0.0f, 1.0f,},
0552: };
0553: m_pd3dDevice->SetTexture(0, m_pXYMap);
0554: m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN
0555: , 2, Vertex2, sizeof( TVERTEX ) );
0556:
0557: RS( D3DRS_ZENABLE, TRUE );
0558: RS( D3DRS_LIGHTING, TRUE );
0559:
0560:
0561: RenderText();
0562:
0563: #if 0
0564: {
0565: m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1);
0566: m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE);
0567: m_pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_DISABLE);
0568: m_pd3dDevice->SetVertexShader(NULL);
0569: m_pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 );
0570: m_pd3dDevice->SetPixelShader(0);
0571: float scale = 128.0f;
0572: for(DWORD i=0; i<3; i++){
0573: TVERTEX Vertex[4] = {
0574:
0575: { 0,(i+0)*scale,0, 1, 0, 0,},
0576: {scale,(i+0)*scale,0, 1, 1, 0,},
0577: {scale,(i+1)*scale,0, 1, 1, 1,},
0578: { 0,(i+1)*scale,0, 1, 0, 1,},
0579: };
0580: if(0==i) m_pd3dDevice->SetTexture( 0, m_pOriginalMap );
0581: if(1==i) m_pd3dDevice->SetTexture( 0, m_pXMap );
0582: if(2==i) m_pd3dDevice->SetTexture( 0, m_pXYMap );
0583: m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, Vertex, sizeof( TVERTEX ) );
0584: }
0585: }
0586: #endif
0587:
0588:
0589: m_pd3dDevice->EndScene();
0590: }
0591:
0592: return S_OK;
0593: }
0594:
0595:
0596:
0597:
0598:
0599:
0600:
0601:
0602: HRESULT CMyD3DApplication::RenderText()
0603: {
0604: D3DCOLOR fontColor = D3DCOLOR_ARGB(255,255,255,0);
0605: TCHAR szMsg[MAX_PATH] = TEXT("");
0606:
0607: FLOAT fNextLine = 40.0f;
0608:
0609:
0610: fNextLine = (FLOAT) m_d3dsdBackBuffer.Height;
0611: sprintf( szMsg, TEXT("Use Page Up/Down keys to change dispersion (Now %f^2)"), m_dispersion_sq );
0612: fNextLine -= 20.0f;
0613: m_pFont->DrawText( 2, fNextLine, fontColor, szMsg );
0614: lstrcpy( szMsg, TEXT("Press 'F2' to configure display") );
0615: fNextLine -= 20.0f;
0616: m_pFont->DrawText( 2, fNextLine, fontColor, szMsg );
0617:
0618: lstrcpy( szMsg, m_strDeviceStats );
0619: fNextLine -= 20.0f;
0620: m_pFont->DrawText( 2, fNextLine, fontColor, szMsg );
0621: lstrcpy( szMsg, m_strFrameStats );
0622: fNextLine -= 20.0f;
0623: m_pFont->DrawText( 2, fNextLine, fontColor, szMsg );
0624:
0625: return S_OK;
0626: }
0627:
0628:
0629:
0630:
0631:
0632:
0633:
0634:
0635: LRESULT CMyD3DApplication::MsgProc( HWND hWnd, UINT msg,
0636: WPARAM wParam, LPARAM lParam )
0637: {
0638: switch( msg )
0639: {
0640: case WM_PAINT:
0641: {
0642: if( m_bLoadingApp )
0643: {
0644:
0645: HDC hDC = GetDC( hWnd );
0646: TCHAR strMsg[MAX_PATH];
0647: wsprintf(strMsg, TEXT("Loading... Please wait"));
0648: RECT rct;
0649: GetClientRect( hWnd, &rct );
0650: DrawText( hDC, strMsg, -1, &rct
0651: , DT_CENTER|DT_VCENTER|DT_SINGLELINE );
0652: ReleaseDC( hWnd, hDC );
0653: }
0654: break;
0655: }
0656:
0657: }
0658:
0659: return CD3DApplication::MsgProc( hWnd, msg, wParam, lParam );
0660: }
0661:
0662:
0663:
0664:
0665:
0666:
0667:
0668:
0669: HRESULT CMyD3DApplication::InvalidateDeviceObjects()
0670: {
0671:
0672: SAFE_RELEASE(m_pXYMapSurf);
0673: SAFE_RELEASE(m_pXYMap);
0674: SAFE_RELEASE(m_pXMapSurf);
0675: SAFE_RELEASE(m_pXMap);
0676: SAFE_RELEASE(m_pOriginalMapSurf);
0677: SAFE_RELEASE(m_pOriginalMap);
0678: SAFE_RELEASE(m_pMapZ);
0679:
0680: m_pMesh ->InvalidateDeviceObjects();
0681: m_pMeshBg->InvalidateDeviceObjects();
0682:
0683: m_pFont->InvalidateDeviceObjects();
0684:
0685:
0686: if( m_pEffect != NULL ) m_pEffect->OnLostDevice();
0687:
0688: return S_OK;
0689: }
0690:
0691:
0692:
0693:
0694:
0695:
0696:
0697:
0698: HRESULT CMyD3DApplication::DeleteDeviceObjects()
0699: {
0700:
0701: SAFE_RELEASE( m_pEffect );
0702:
0703:
0704: m_pMesh ->Destroy();
0705: m_pMeshBg->Destroy();
0706:
0707:
0708: m_pFont->DeleteDeviceObjects();
0709:
0710: return S_OK;
0711: }
0712:
0713:
0714:
0715:
0716:
0717:
0718:
0719:
0720: HRESULT CMyD3DApplication::FinalCleanup()
0721: {
0722: SAFE_DELETE( m_pMeshBg );
0723: SAFE_DELETE( m_pMesh );
0724:
0725: SAFE_DELETE( m_pFont );
0726:
0727: return S_OK;
0728: }
0729:
0730:
0731:
0732:
0733: