0001:
0002:
0003:
0004:
0005:
0006:
0007:
0008:
0009: #include "dxstdafx.h"
0010: #include "resource.h"
0011: #include "main_fx.h"
0012:
0013:
0014:
0015:
0016:
0017:
0018:
0019:
0020:
0021:
0022: struct VERTEX
0023: {
0024: D3DXVECTOR3 pos;
0025: D3DXVECTOR2 tex;
0026:
0027: static const DWORD FVF;
0028: };
0029: const DWORD VERTEX::FVF = D3DFVF_XYZ | D3DFVF_TEX1;
0030:
0031:
0032:
0033:
0034:
0035: IDirect3DDevice9* g_pd3dDevice = NULL;
0036: ID3DXFont* g_pFont = NULL;
0037:
0038: ID3DXSprite* g_pTextSprite = NULL;
0039:
0040: ID3DXEffect* g_pEffect = NULL;
0041:
0042: CModelViewerCamera g_Camera;
0043:
0044: bool g_bShowHelp = true;
0045:
0046: CDXUTDialog g_HUD;
0047:
0048: CDXUTDialog g_SampleUI;
0049:
0050:
0051: D3DVIEWPORT9 g_ViewportFB;
0052:
0053: VERTEX g_Vertex[4];
0054: LPDIRECT3DTEXTURE9 g_pWangTexture = NULL;
0055:
0056: DWORD g_MapSize = 32;
0057: LPDIRECT3DTEXTURE9 g_pRandTexture = NULL;
0058:
0059:
0060:
0061:
0062:
0063:
0064: #define IDC_TOGGLEFULLSCREEN 1
0065: #define IDC_TOGGLEREF 2
0066: #define IDC_CHANGEDEVICE 3
0067: #define IDC_CHANGE_LEVEL_STATIC 4
0068: #define IDC_CHANGE_LEVEL 5
0069:
0070:
0071:
0072:
0073:
0074:
0075:
0076: bool CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, bool bWindowed );
0077: void CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps );
0078: HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc );
0079: HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc );
0080: void CALLBACK OnFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime );
0081: void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime );
0082: LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing );
0083: void CALLBACK KeyboardProc( UINT nChar, bool bKeyDown, bool bAltDown );
0084: void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl );
0085: void CALLBACK OnLostDevice();
0086: void CALLBACK OnDestroyDevice();
0087:
0088: void InitApp();
0089: HRESULT LoadMesh( IDirect3DDevice9* pd3dDevice, WCHAR* strFileName, ID3DXMesh** ppMesh );
0090: void RenderText();
0091:
0092:
0093:
0094:
0095:
0096:
0097:
0098:
0099: INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
0100: {
0101:
0102:
0103:
0104:
0105:
0106:
0107:
0108:
0109: DXUTSetCallbackDeviceCreated( OnCreateDevice );
0110: DXUTSetCallbackDeviceReset( OnResetDevice );
0111: DXUTSetCallbackDeviceLost( OnLostDevice );
0112: DXUTSetCallbackDeviceDestroyed( OnDestroyDevice );
0113: DXUTSetCallbackMsgProc( MsgProc );
0114: DXUTSetCallbackKeyboard( KeyboardProc );
0115: DXUTSetCallbackFrameRender( OnFrameRender );
0116: DXUTSetCallbackFrameMove( OnFrameMove );
0117:
0118:
0119: DXUTSetCursorSettings( true, true );
0120:
0121: InitApp();
0122:
0123:
0124:
0125:
0126: DXUTInit( true, true, true );
0127: DXUTCreateWindow( L"main" );
0128: DXUTCreateDevice( D3DADAPTER_DEFAULT, true, 640, 480, IsDeviceAcceptable, ModifyDeviceSettings );
0129:
0130:
0131:
0132:
0133: DXUTMainLoop();
0134:
0135:
0136:
0137:
0138: return DXUTGetExitCode();
0139: }
0140:
0141:
0142:
0143:
0144:
0145:
0146: void InitApp()
0147: {
0148: g_pEffect = NULL;
0149:
0150: g_Vertex[0].pos = D3DXVECTOR3(+1,0,-1);
0151: g_Vertex[1].pos = D3DXVECTOR3(-1,0,-1);
0152: g_Vertex[2].pos = D3DXVECTOR3(+1,0,+1);
0153: g_Vertex[3].pos = D3DXVECTOR3(-1,0,+1);
0154: g_Vertex[0].tex = D3DXVECTOR2(1,1);
0155: g_Vertex[1].tex = D3DXVECTOR2(0,1);
0156: g_Vertex[2].tex = D3DXVECTOR2(1,0);
0157: g_Vertex[3].tex = D3DXVECTOR2(0,0);
0158:
0159:
0160:
0161: g_HUD.SetCallback( OnGUIEvent ); int iY = 10;
0162: g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 35, iY, 125, 22 );
0163: g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 35, iY += 24, 125, 22 );
0164: g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 35, iY += 24, 125, 22 );
0165:
0166: g_SampleUI.SetCallback( OnGUIEvent ); iY = 10;
0167:
0168:
0169:
0170:
0171:
0172:
0173:
0174:
0175:
0176:
0177:
0178:
0179:
0180:
0181:
0182:
0183:
0184:
0185:
0186:
0187:
0188: WCHAR sz[100];
0189: iY += 256;
0190: _snwprintf( sz, 100, L"SIZE: %3d", g_MapSize ); sz[99] = 0;
0191: g_SampleUI.AddStatic( IDC_CHANGE_LEVEL_STATIC, sz, 35, iY += 24, 125, 22 );
0192: g_SampleUI.AddSlider( IDC_CHANGE_LEVEL, -150, iY += 24, 300, 22, 1, 256, (int)g_MapSize );
0193: }
0194:
0195:
0196:
0197:
0198:
0199: bool CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat,
0200: D3DFORMAT BackBufferFormat, bool bWindowed )
0201: {
0202:
0203:
0204: IDirect3D9* pD3D = DXUTGetD3DObject();
0205: if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType,
0206: AdapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,
0207: D3DRTYPE_TEXTURE, BackBufferFormat ) ) )
0208: return false;
0209:
0210:
0211: if( pCaps->VertexShaderVersion < D3DVS_VERSION( 1, 1 ) )
0212: return false;
0213:
0214:
0215: if( pCaps->PixelShaderVersion < D3DPS_VERSION( 2, 0 ) )
0216: return false;
0217:
0218: return true;
0219: }
0220:
0221:
0222:
0223:
0224:
0225:
0226:
0227:
0228:
0229:
0230: void CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps )
0231: {
0232:
0233:
0234: if( (pCaps->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 ||
0235: pCaps->VertexShaderVersion < D3DVS_VERSION(1,1) )
0236: {
0237: pDeviceSettings->BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
0238: }
0239: else
0240: {
0241: pDeviceSettings->BehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
0242: }
0243:
0244:
0245:
0246: if ((pCaps->DevCaps & D3DDEVCAPS_PUREDEVICE) != 0 &&
0247: (pDeviceSettings->BehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING) != 0 )
0248: pDeviceSettings->BehaviorFlags |= D3DCREATE_PUREDEVICE;
0249:
0250:
0251:
0252: #ifdef DEBUG_VS
0253: if( pDeviceSettings->DeviceType != D3DDEVTYPE_REF )
0254: {
0255: pDeviceSettings->BehaviorFlags &= ~D3DCREATE_HARDWARE_VERTEXPROCESSING;
0256: pDeviceSettings->BehaviorFlags &= ~D3DCREATE_PUREDEVICE;
0257: pDeviceSettings->BehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
0258: }
0259: #endif
0260: #ifdef DEBUG_PS
0261: pDeviceSettings->DeviceType = D3DDEVTYPE_REF;
0262: #endif
0263: }
0264:
0265:
0266:
0267:
0268: #define frand() ((FLOAT)rand()/(FLOAT)RAND_MAX)
0269:
0270: VOID WINAPI FillRand (D3DXVECTOR4* pOut, CONST D3DXVECTOR2* pTexCoord,
0271: CONST D3DXVECTOR2* pTexelSize, LPVOID pData)
0272: {
0273: UNREFERENCED_PARAMETER( pTexCoord );
0274: UNREFERENCED_PARAMETER( pTexelSize );
0275: UNREFERENCED_PARAMETER( pData );
0276:
0277: pOut->x = frand();
0278: pOut->y = frand();
0279: pOut->z = pOut->w = 0.0f;
0280: }
0281:
0282:
0283:
0284:
0285:
0286:
0287:
0288:
0289:
0290: HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc )
0291: {
0292: HRESULT hr;
0293: WCHAR str[MAX_PATH];
0294:
0295: g_pd3dDevice = pd3dDevice;
0296:
0297:
0298: V_RETURN( D3DXCreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,
0299: OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
0300: L"Arial", &g_pFont ) );
0301:
0302:
0303: V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"wang.bmp" ) );
0304: V_RETURN( D3DXCreateTextureFromFile( pd3dDevice, str, &g_pWangTexture) );
0305:
0306: V_RETURN( pd3dDevice->CreateTexture( g_MapSize, g_MapSize, 1
0307: , 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &g_pRandTexture, NULL));
0308: V_RETURN( D3DXFillTexture( g_pRandTexture, FillRand, NULL ));
0309:
0310:
0311:
0312:
0313:
0314:
0315:
0316:
0317:
0318:
0319:
0320:
0321:
0322: DWORD dwShaderFlags = 0;
0323: #ifdef DEBUG_VS
0324: dwShaderFlags |= D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT;
0325: #endif
0326: #ifdef DEBUG_PS
0327: dwShaderFlags |= D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT;
0328: #endif
0329:
0330:
0331:
0332: V_RETURN( D3DXCreateEffect( pd3dDevice, g_effect, sizeof(g_effect),
0333: NULL, NULL, dwShaderFlags, NULL, &g_pEffect, NULL ) );
0334:
0335:
0336:
0337: D3DXVECTOR3 vecEye(0.0f, 3.0f, -3.0f);
0338: D3DXVECTOR3 vecAt (0.0f, 0.0f, -0.0f);
0339: g_Camera.SetViewParams( &vecEye, &vecAt );
0340:
0341: return S_OK;
0342: }
0343:
0344:
0345:
0346:
0347:
0348:
0349:
0350: HRESULT LoadMesh( IDirect3DDevice9* pd3dDevice, WCHAR* strFileName, ID3DXMesh** ppMesh )
0351: {
0352: ID3DXMesh* pMesh = NULL;
0353: WCHAR str[MAX_PATH];
0354: HRESULT hr;
0355:
0356:
0357:
0358:
0359:
0360: V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, strFileName ) );
0361:
0362: V_RETURN( D3DXLoadMeshFromX(str, D3DXMESH_MANAGED, pd3dDevice, NULL, NULL, NULL, NULL, &pMesh) );
0363:
0364: DWORD *rgdwAdjacency = NULL;
0365:
0366:
0367: if( !(pMesh->GetFVF() & D3DFVF_NORMAL) )
0368: {
0369: ID3DXMesh* pTempMesh;
0370: V( pMesh->CloneMeshFVF( pMesh->GetOptions(),
0371: pMesh->GetFVF() | D3DFVF_NORMAL,
0372: pd3dDevice, &pTempMesh ) );
0373: V( D3DXComputeNormals( pTempMesh, NULL ) );
0374:
0375: SAFE_RELEASE( pMesh );
0376: pMesh = pTempMesh;
0377: }
0378:
0379:
0380:
0381:
0382:
0383: rgdwAdjacency = new DWORD[pMesh->GetNumFaces() * 3];
0384: if( rgdwAdjacency == NULL )
0385: return E_OUTOFMEMORY;
0386: V( pMesh->ConvertPointRepsToAdjacency(NULL, rgdwAdjacency) );
0387: V( pMesh->OptimizeInplace(D3DXMESHOPT_VERTEXCACHE, rgdwAdjacency, NULL, NULL, NULL) );
0388: delete []rgdwAdjacency;
0389:
0390: *ppMesh = pMesh;
0391:
0392: return S_OK;
0393: }
0394:
0395:
0396:
0397:
0398:
0399:
0400:
0401:
0402:
0403: HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice,
0404: const D3DSURFACE_DESC* pBackBufferSurfaceDesc )
0405: {
0406: HRESULT hr;
0407:
0408: pd3dDevice->GetViewport(&g_ViewportFB);
0409:
0410:
0411: if( g_pFont )
0412: V_RETURN( g_pFont->OnResetDevice() );
0413: if( g_pEffect )
0414: V_RETURN( g_pEffect->OnResetDevice() );
0415:
0416:
0417: V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pTextSprite ) );
0418:
0419:
0420: float fAspectRatio = pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height;
0421: g_Camera.SetProjParams( D3DX_PI/4, fAspectRatio, 0.1f, 1000.0f );
0422: g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );
0423:
0424: g_HUD.SetLocation( pBackBufferSurfaceDesc->Width-170, 0 );
0425: g_HUD.SetSize( 170, 170 );
0426: g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width-170, pBackBufferSurfaceDesc->Height-350 );
0427: g_SampleUI.SetSize( 170, 300 );
0428:
0429: return S_OK;
0430: }
0431:
0432:
0433:
0434:
0435:
0436:
0437:
0438:
0439: void CALLBACK OnFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime )
0440: {
0441:
0442: g_Camera.FrameMove( fElapsedTime );
0443: }
0444:
0445:
0446:
0447:
0448:
0449:
0450:
0451:
0452:
0453: void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime )
0454: {
0455: HRESULT hr;
0456: UINT iPass, cPasses;
0457: D3DXMATRIXA16 mWorld;
0458: D3DXMATRIXA16 mCamera;
0459: D3DXMATRIXA16 mView;
0460: D3DXMATRIXA16 mProj;
0461: D3DXMATRIXA16 mWorldViewProjection;
0462:
0463:
0464: V( pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 45, 50, 170), 1.0f, 0) );
0465:
0466:
0467: if( SUCCEEDED( pd3dDevice->BeginScene() ) )
0468: {
0469:
0470: mCamera = *g_Camera.GetWorldMatrix();
0471: mView = *g_Camera.GetViewMatrix();
0472: mProj = *g_Camera.GetProjMatrix();
0473:
0474: mWorldViewProjection = mCamera * mView * mProj;
0475:
0476:
0477: V( g_pEffect->SetTechnique( "WangTechnique" ) );
0478:
0479:
0480:
0481:
0482: V( g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection ) );
0483:
0484: V( g_pEffect->SetTexture( "WangTexture", g_pWangTexture ) );
0485: V( g_pEffect->SetTexture( "RandTexture", g_pRandTexture ) );
0486: V( g_pEffect->SetFloat( "g_fTexSize", (float)g_MapSize ) );
0487: V( g_pEffect->SetFloat( "g_fInvTexSize", 1.0f/(float)g_MapSize ) );
0488:
0489: pd3dDevice->SetFVF( VERTEX::FVF );
0490:
0491: V( g_pEffect->Begin(&cPasses, 0) );
0492: for (iPass = 0; iPass < cPasses; iPass++)
0493: {
0494: V( g_pEffect->BeginPass(iPass) );
0495: pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP,2, g_Vertex, sizeof(VERTEX) );
0496: V( g_pEffect->EndPass() );
0497: }
0498: V( g_pEffect->End() );
0499:
0500:
0501:
0502: DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
0503: RenderText();
0504: V( g_HUD.OnRender( fElapsedTime ) );
0505: V( g_SampleUI.OnRender( fElapsedTime ) );
0506: DXUT_EndPerfEvent();
0507:
0508: #ifdef _DEBUG
0509: {
0510: pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1);
0511: pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE);
0512: pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_DISABLE);
0513: pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
0514: pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
0515: pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 );
0516: float scale = 64.0f;
0517: typedef struct { FLOAT p[4]; FLOAT tu, tv;} TVERTEX;
0518:
0519: for(DWORD i=0; i<2; i++){
0520: TVERTEX Vertex[4] = {
0521:
0522: {(i+0)*scale, (FLOAT)g_ViewportFB.Height-scale, 0, 1, 0, 0,},
0523: {(i+1)*scale, (FLOAT)g_ViewportFB.Height-scale, 0, 1, 1, 0,},
0524: {(i+1)*scale, (FLOAT)g_ViewportFB.Height- 0, 0, 1, 1, 1,},
0525: {(i+0)*scale, (FLOAT)g_ViewportFB.Height- 0, 0, 1, 0, 1,},
0526: };
0527: if(0==i) pd3dDevice->SetTexture( 0, g_pWangTexture );
0528: if(1==i) pd3dDevice->SetTexture( 0, g_pRandTexture );
0529:
0530: pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, Vertex, sizeof( TVERTEX ) );
0531: }
0532: }
0533: #endif
0534:
0535: V( pd3dDevice->EndScene() );
0536: }
0537: }
0538:
0539:
0540:
0541:
0542:
0543:
0544: void RenderText()
0545: {
0546:
0547:
0548:
0549:
0550: const D3DSURFACE_DESC* pd3dsdBackBuffer = DXUTGetBackBufferSurfaceDesc();
0551: CDXUTTextHelper txtHelper( g_pFont, g_pTextSprite, 15 );
0552:
0553:
0554: txtHelper.Begin();
0555: txtHelper.SetInsertionPos( 5, 5 );
0556: txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 0.0f, 1.0f ) );
0557: txtHelper.DrawTextLine( DXUTGetFrameStats() );
0558: txtHelper.DrawTextLine( DXUTGetDeviceStats() );
0559:
0560: txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );
0561: txtHelper.DrawTextLine( L"Put whatever misc status here" );
0562:
0563:
0564: if( g_bShowHelp )
0565: {
0566: txtHelper.SetInsertionPos( 10, pd3dsdBackBuffer->Height-15*3 );
0567: txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 0.75f, 0.0f, 1.0f ) );
0568: txtHelper.DrawTextLine( L"Controls (F1 to hide):" );
0569:
0570: txtHelper.SetInsertionPos( 40, pd3dsdBackBuffer->Height-15*5 );
0571: txtHelper.DrawTextLine( L"Quit: ESC" );
0572: }
0573: else
0574: {
0575: txtHelper.SetInsertionPos( 10, pd3dsdBackBuffer->Height-15*2 );
0576: txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );
0577: txtHelper.DrawTextLine( L"Press F1 for help" );
0578: }
0579: txtHelper.End();
0580: }
0581:
0582:
0583:
0584:
0585:
0586:
0587:
0588: LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing )
0589: {
0590:
0591: *pbNoFurtherProcessing = g_HUD.MsgProc( hWnd, uMsg, wParam, lParam );
0592: if( *pbNoFurtherProcessing )
0593: return 0;
0594: *pbNoFurtherProcessing = g_SampleUI.MsgProc( hWnd, uMsg, wParam, lParam );
0595: if( *pbNoFurtherProcessing )
0596: return 0;
0597:
0598:
0599: g_Camera.HandleMessages( hWnd, uMsg, wParam, lParam );
0600:
0601: return 0;
0602: }
0603:
0604:
0605:
0606:
0607:
0608:
0609:
0610:
0611: void CALLBACK KeyboardProc( UINT nChar, bool bKeyDown, bool bAltDown )
0612: {
0613: if( bKeyDown )
0614: {
0615: switch( nChar )
0616: {
0617: case VK_F1: g_bShowHelp = !g_bShowHelp; break;
0618: }
0619: }
0620: }
0621:
0622:
0623:
0624:
0625:
0626: void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl )
0627: {
0628: switch( nControlID )
0629: {
0630: case IDC_TOGGLEFULLSCREEN: DXUTToggleFullScreen(); break;
0631: case IDC_TOGGLEREF: DXUTToggleREF(); break;
0632: case IDC_CHANGEDEVICE: DXUTSetShowSettingsDialog( !DXUTGetShowSettingsDialog() ); break;
0633: case IDC_CHANGE_LEVEL:
0634: {
0635: WCHAR sz[100];
0636: g_MapSize = g_SampleUI.GetSlider( IDC_CHANGE_LEVEL )->GetValue();
0637: _snwprintf( sz, 100, L"SIZE: %3d", g_MapSize ); sz[99] = 0;
0638: g_SampleUI.GetStatic( IDC_CHANGE_LEVEL_STATIC )->SetText( sz );
0639:
0640: if( g_pRandTexture )
0641: {
0642: SAFE_RELEASE( g_pRandTexture );
0643: g_pd3dDevice->CreateTexture( g_MapSize, g_MapSize, 1
0644: , 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &g_pRandTexture, NULL);
0645: D3DXFillTexture( g_pRandTexture, FillRand, NULL );
0646: }
0647:
0648: break;
0649: }
0650: }
0651: }
0652:
0653:
0654:
0655:
0656:
0657:
0658:
0659:
0660:
0661: void CALLBACK OnLostDevice()
0662: {
0663: if( g_pFont )
0664: g_pFont->OnLostDevice();
0665: if( g_pEffect )
0666: g_pEffect->OnLostDevice();
0667: SAFE_RELEASE( g_pTextSprite );
0668: }
0669:
0670:
0671:
0672:
0673:
0674:
0675:
0676:
0677: void CALLBACK OnDestroyDevice()
0678: {
0679: SAFE_RELEASE( g_pEffect );
0680: SAFE_RELEASE( g_pFont );
0681:
0682: SAFE_RELEASE( g_pRandTexture );
0683: SAFE_RELEASE( g_pWangTexture );
0684: }
0685:
0686:
0687:
0688: