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