home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8a_sdk.exe / samples / multimedia / direct3d / mfctex / mtexture.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-04  |  18.8 KB  |  515 lines

  1. //-----------------------------------------------------------------------------
  2. // File: mtexture.cpp
  3. //
  4. // Desc: Example code showing how to do multitexturing in D3D
  5. //
  6. //       Note: This code uses the D3D Framework helper library.
  7. //
  8. // Copyright (c) 1997-2000 Microsoft Corporation. All rights reserved.
  9. //-----------------------------------------------------------------------------
  10. #define STRICT
  11. #include "stdafx.h"
  12. #include <tchar.h>
  13. #include <math.h>
  14. #include <time.h>
  15. #include <stdio.h>
  16. #include <D3DX8.h>
  17. #include "D3DApp.h"
  18. #include "D3DFont.h"
  19. #include "D3DFile.h"
  20. #include "D3DUtil.h"
  21. #include "DXUtil.h"
  22. #include "MFCTex.h"
  23.  
  24.  
  25.  
  26.  
  27. //-----------------------------------------------------------------------------
  28. // Define a custom vertex that uses multiple sets of tex coords
  29. //-----------------------------------------------------------------------------
  30. struct WALLVERTEX
  31. {
  32.     D3DXVECTOR3 p;
  33.     DWORD dwColor;
  34.     FLOAT tu1, tv1;
  35.     FLOAT tu2, tv2;
  36.     FLOAT tu3, tv3;
  37. };
  38.  
  39. #define D3DFVF_WALLVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX3 )
  40.  
  41. #define FILL_WALLVERTEX( v, ax, ay, az, acolor, atu1, atv1, atu2, atv2, atu3, atv3 )  \
  42. {   v.p.x = ax; v.p.y = ay; v.p.z = az; v.dwColor  = acolor; \
  43.     v.tu1 = atu1; v.tv1 = atv1; v.tu2 = atu2; v.tv2 = atv2;\
  44.     v.tu3 = atu3; v.tv3 = atv3;\
  45. }
  46.  
  47. #define WALL_VERT_NUM 10
  48.  
  49.  
  50. struct FLOORCEILINGVERTEX
  51. {
  52.     D3DXVECTOR3 p;
  53.     D3DXVECTOR3 n;
  54.     FLOAT tu, tv;
  55. };
  56.  
  57. #define D3DFVF_FLOORCEILINGVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 )
  58.  
  59. #define FILL_FLOORCEILINGVERTEX( v, ax, ay, az, nx, ny, nz, atu, atv )  \
  60. {   v.p.x = ax; v.p.y = ay; v.p.z = az; v.n.x = nx; v.n.y = ny; v.n.z = nz; \
  61.     v.tu = atu; v.tv = atv; \
  62. }
  63.  
  64. #define FLOORCEILING_VERT_NUM 12
  65.  
  66.  
  67.  
  68. //-----------------------------------------------------------------------------
  69. // Storage of the texture stage states
  70. //-----------------------------------------------------------------------------
  71. WORD  g_wT0COp,   g_wT1COp,   g_wT2COp;
  72. WORD  g_wT0CArg1, g_wT1CArg1, g_wT2CArg1;
  73. WORD  g_wT0CArg2, g_wT1CArg2, g_wT2CArg2;
  74. WORD  g_wT0AOp,   g_wT1AOp,   g_wT2AOp;
  75. WORD  g_wT0AArg1, g_wT1AArg1, g_wT2AArg1;
  76. WORD  g_wT0AArg2, g_wT1AArg2, g_wT2AArg2;
  77. DWORD g_dwTextureFactor         = 0xffffffff;
  78. DWORD g_dwDiffuseColor          = 0xffffffff;
  79. DWORD g_dwMaxTextureBlendStages = 0;
  80.  
  81.  
  82.  
  83.  
  84.  
  85. //-----------------------------------------------------------------------------
  86. // Function prototypes and global (or static) variables
  87. //-----------------------------------------------------------------------------
  88. LPDIRECT3DTEXTURE8 g_pFloorTexture = NULL;
  89. LPDIRECT3DTEXTURE8 g_pTexture0     = NULL;
  90. LPDIRECT3DTEXTURE8 g_pTexture1     = NULL;
  91. LPDIRECT3DTEXTURE8 g_pTexture2     = NULL;
  92.  
  93. // Filenames for the textures (one for each texture stage)
  94. BOOL  g_bTexturesChanged = FALSE;
  95. TCHAR g_strTexture0[256];
  96. TCHAR g_strTexture1[256];
  97. TCHAR g_strTexture2[256];
  98.  
  99.  
  100.  
  101.  
  102. //-----------------------------------------------------------------------------
  103. // Name: OneTimeSceneInit()
  104. // Desc: Called during initial app startup, this function performs all the
  105. //       permanent initialization.
  106. //-----------------------------------------------------------------------------
  107. HRESULT CAppForm::OneTimeSceneInit()
  108. {
  109.     m_pFont = new CD3DFont( _T("Arial"), 9, D3DFONT_BOLD );
  110.  
  111.     // Create some textures
  112.     _tcscpy( g_strTexture0, _T("env2.bmp") );
  113.     _tcscpy( g_strTexture1, _T("spotlite.bmp") );
  114.     _tcscpy( g_strTexture2, _T("env3.bmp") );
  115.  
  116.     g_pFloorTexture = NULL;
  117.     g_pTexture0     = NULL;
  118.     g_pTexture1     = NULL;
  119.     g_pTexture2     = NULL;
  120.  
  121.     return S_OK;
  122. }
  123.  
  124.  
  125.  
  126.  
  127. //-----------------------------------------------------------------------------
  128. // Name: FrameMove()
  129. // Desc: Called once per frame, the call is the entry point for animating
  130. //       the scene.
  131. //-----------------------------------------------------------------------------
  132. HRESULT CAppForm::FrameMove()
  133. {
  134.     // Setup the world spin matrix
  135.     D3DXMATRIX matWorldSpin;
  136.     D3DXMatrixRotationY( &matWorldSpin, -m_fTime/9 );
  137.     m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorldSpin );
  138.  
  139.     // keep texture coordinates in a reasonable range
  140.     static FLOAT fTimeKeySub = 0.0f;
  141.     FLOAT fTexTimeKey = m_fTime + fTimeKeySub;
  142.     if( fTexTimeKey > 160.0f )
  143.     {
  144.         fTimeKeySub -= 160.0f;
  145.     }
  146.  
  147.     WALLVERTEX* pVertices;
  148.     m_pVBWalls->Lock( 0, 0, (BYTE**)&pVertices, 0 );
  149.     // Rotate the light map around the walls each frame
  150.     for( int i=0; i<(WALL_VERT_NUM/2); i++ )
  151.     {
  152.         pVertices[2*i+0].tu2 = fTexTimeKey/(WALL_VERT_NUM/2)+i;
  153.         pVertices[2*i+1].tu2 = fTexTimeKey/(WALL_VERT_NUM/2)+i;
  154.     }
  155.     for( i=0; i<WALL_VERT_NUM; i++ )
  156.         pVertices[i].dwColor = g_dwDiffuseColor;
  157.     m_pVBWalls->Unlock();
  158.  
  159.     return S_OK;
  160. }
  161.  
  162.  
  163.  
  164.  
  165. //-----------------------------------------------------------------------------
  166. // Name: SetTextureStageStatesForRendering()
  167. // Desc: Sets up the texture stage, as per the global variables defining each
  168. //       stage.
  169. //-----------------------------------------------------------------------------
  170. HRESULT SetTextureStageStatesForRendering( LPDIRECT3DDEVICE8 pd3dDevice )
  171. {
  172.     // If new textures were selected, restore them now
  173.     if( g_bTexturesChanged )
  174.     {
  175.         SAFE_RELEASE( g_pFloorTexture );
  176.         SAFE_RELEASE( g_pTexture0 );
  177.         SAFE_RELEASE( g_pTexture1 );
  178.         SAFE_RELEASE( g_pTexture2 );
  179.         if( FAILED( D3DUtil_CreateTexture( pd3dDevice, _T("floor.bmp"), &g_pFloorTexture ) ) )
  180.             return E_FAIL;
  181.         if( FAILED( D3DUtil_CreateTexture( pd3dDevice, g_strTexture0, &g_pTexture0 ) ) )
  182.             return E_FAIL;
  183.         if( FAILED( D3DUtil_CreateTexture( pd3dDevice, g_strTexture1, &g_pTexture1 ) ) )
  184.             return E_FAIL;
  185.         if( FAILED( D3DUtil_CreateTexture( pd3dDevice, g_strTexture2, &g_pTexture2 ) ) )
  186.             return E_FAIL;
  187.         g_bTexturesChanged = FALSE;
  188.     }
  189.  
  190.     pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, g_dwTextureFactor );
  191.  
  192.     pd3dDevice->SetTexture( 0, g_pTexture0 );
  193.     pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
  194.     pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
  195.     pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, g_wT0CArg1 );
  196.     pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   g_wT0COp   );
  197.     pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, g_wT0CArg2 );
  198.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, g_wT0AArg1 );
  199.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   g_wT0AOp   );
  200.     pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, g_wT0AArg2 );
  201.  
  202.     if( g_dwMaxTextureBlendStages > 1 )
  203.     {
  204.         pd3dDevice->SetTexture( 1, g_pTexture1 );
  205.         pd3dDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1 );
  206.         pd3dDevice->SetTextureStageState( 1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
  207.         pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, g_wT1CArg1 );
  208.         pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   g_wT1COp   );
  209.         pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, g_wT1CArg2 );
  210.         pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, g_wT1AArg1 );
  211.         pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   g_wT1AOp   );
  212.         pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2, g_wT1AArg2 );
  213.     }
  214.  
  215.     if( g_dwMaxTextureBlendStages > 2)
  216.     {
  217.         pd3dDevice->SetTexture( 2, g_pTexture2 );
  218.         pd3dDevice->SetTextureStageState( 2, D3DTSS_TEXCOORDINDEX, 0 );
  219.         pd3dDevice->SetTextureStageState( 2, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
  220.         pd3dDevice->SetTextureStageState( 2, D3DTSS_COLORARG1, g_wT2CArg1 );
  221.         pd3dDevice->SetTextureStageState( 2, D3DTSS_COLOROP,   g_wT2COp   );
  222.         pd3dDevice->SetTextureStageState( 2, D3DTSS_COLORARG2, g_wT2CArg2 );
  223.         pd3dDevice->SetTextureStageState( 2, D3DTSS_ALPHAARG1, g_wT2AArg1 );
  224.         pd3dDevice->SetTextureStageState( 2, D3DTSS_ALPHAOP,   g_wT2AOp   );
  225.         pd3dDevice->SetTextureStageState( 2, D3DTSS_ALPHAARG2, g_wT2AArg2 );
  226.     }
  227.  
  228.     return S_OK;
  229. }
  230.  
  231.  
  232.  
  233.  
  234. //-----------------------------------------------------------------------------
  235. // Name: Render()
  236. // Desc: Called once per frame, the call is the entry point for 3d
  237. //       rendering. This function sets up render states, clears the
  238. //       viewport, and renders the scene.
  239. //-----------------------------------------------------------------------------
  240. HRESULT CAppForm::Render()
  241. {
  242.     HRESULT hr;
  243.  
  244.     m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
  245.                        0x000000ff, 1.0f, 0L );
  246.  
  247.     // Begin the scene
  248.     if( FAILED( m_pd3dDevice->BeginScene() ) )
  249.         return E_FAIL;
  250.  
  251.     // Render the floor and ceiling (using single-textured vertices)
  252.     m_pd3dDevice->SetTexture( 0, g_pFloorTexture );
  253.     m_pd3dDevice->SetTexture( 1, NULL );
  254.     m_pd3dDevice->SetTexture( 2, NULL );
  255.  
  256.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
  257.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  258.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
  259.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
  260.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
  261.     m_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLOROP,   D3DTOP_DISABLE );
  262.     m_pd3dDevice->SetTextureStageState( 2, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
  263.  
  264.     m_pd3dDevice->SetVertexShader( D3DFVF_FLOORCEILINGVERTEX );
  265.     m_pd3dDevice->SetStreamSource( 0, m_pVBFloorCeiling, sizeof(FLOORCEILINGVERTEX) );
  266.     m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 4 );
  267.  
  268.     // Setup the texture stages' state
  269.     SetTextureStageStatesForRendering( m_pd3dDevice );
  270.  
  271.     // Validate the device. This checks to see if the texture stage states we
  272.     // set up are valid for the device. If so, render the object.
  273.     DWORD dwNumPasses;
  274.     if( SUCCEEDED( hr = m_pd3dDevice->ValidateDevice( &dwNumPasses ) ) )
  275.     {
  276.         // Render the multi-textured object
  277.         m_pd3dDevice->SetVertexShader( D3DFVF_WALLVERTEX );
  278.         m_pd3dDevice->SetStreamSource( 0, m_pVBWalls, sizeof(WALLVERTEX) );
  279.         m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 8);
  280.     }
  281.  
  282.     TCHAR* pstr;
  283.     switch( hr )
  284.     {
  285.     case D3DERR_UNSUPPORTEDCOLOROPERATION:
  286.         pstr = _T("Unsupported color op");
  287.         break;
  288.     case D3DERR_UNSUPPORTEDCOLORARG:
  289.         pstr = _T("Unsupported color arg");
  290.         break;
  291.     case D3DERR_UNSUPPORTEDALPHAOPERATION:
  292.         pstr = _T("Unsupported alpha op");
  293.         break;
  294.     case D3DERR_UNSUPPORTEDALPHAARG:
  295.         pstr = _T("Unsupported alpha arg");
  296.         break;
  297.     case D3DERR_TOOMANYOPERATIONS:
  298.         pstr = _T("Too many texture ops");
  299.         break;
  300.     case D3DERR_WRONGTEXTUREFORMAT:
  301.         pstr = _T("Incompatible texture formats");
  302.         break;
  303.     case D3DERR_CONFLICTINGRENDERSTATE:
  304.         pstr = _T("Conflicting render state");
  305.         break;
  306.     case S_OK:
  307.         pstr = _T("Device validated OK");
  308.         break;
  309.     default:
  310.         pstr = _T("Using DX5 driver");
  311.         break;
  312.     }
  313.     m_pFont->DrawText( 2,  0, D3DCOLOR_ARGB(255,255,255,0), pstr );
  314.  
  315.     // End the scene.
  316.     m_pd3dDevice->EndScene();
  317.  
  318.     return S_OK;
  319. }
  320.  
  321.  
  322.  
  323.  
  324. //-----------------------------------------------------------------------------
  325. // Name: InitDeviceObjects()
  326. // Desc: Initialize scene objects.
  327. //-----------------------------------------------------------------------------
  328. HRESULT CAppForm::InitDeviceObjects()
  329. {
  330.     UpdateUIForDeviceCapabilites();
  331.  
  332.     // Initialize the font's internal textures
  333.     m_pFont->InitDeviceObjects( m_pd3dDevice );
  334.  
  335.     // Create the walls vertex buffer
  336.     if( FAILED( m_pd3dDevice->CreateVertexBuffer( WALL_VERT_NUM * sizeof(WALLVERTEX),
  337.         0, D3DFVF_WALLVERTEX, D3DPOOL_MANAGED, &m_pVBWalls ) ) )
  338.     {
  339.         return E_FAIL;
  340.     }
  341.  
  342.     WALLVERTEX* pVertices;
  343.     m_pVBWalls->Lock( 0, 0, (BYTE**)&pVertices, 0 );
  344.  
  345.     FILL_WALLVERTEX( pVertices[ 0], -5.0f,-5.0f, 5.0f, g_dwDiffuseColor, 0.00f, 1.0f, 1.00, 1.0f, 1.00, 1.0f );
  346.     FILL_WALLVERTEX( pVertices[ 1], -5.0f, 5.0f, 5.0f, g_dwDiffuseColor, 0.00f, 0.0f, 1.00, 0.0f, 1.00, 0.0f );
  347.     FILL_WALLVERTEX( pVertices[ 2],  5.0f,-5.0f, 5.0f, g_dwDiffuseColor, 1.00f, 1.0f, 0.00, 1.0f, 0.00, 1.0f );
  348.     FILL_WALLVERTEX( pVertices[ 3],  5.0f, 5.0f, 5.0f, g_dwDiffuseColor, 1.00f, 0.0f, 0.00, 0.0f, 0.00, 0.0f );
  349.     FILL_WALLVERTEX( pVertices[ 4],  5.0f,-5.0f,-5.0f, g_dwDiffuseColor, 2.00f, 1.0f, 1.00, 1.0f, 1.00, 1.0f );
  350.     FILL_WALLVERTEX( pVertices[ 5],  5.0f, 5.0f,-5.0f, g_dwDiffuseColor, 2.00f, 0.0f, 1.00, 0.0f, 1.00, 0.0f );
  351.     FILL_WALLVERTEX( pVertices[ 6], -5.0f,-5.0f,-5.0f, g_dwDiffuseColor, 3.00f, 1.0f, 1.00, 1.0f, 1.00, 1.0f );
  352.     FILL_WALLVERTEX( pVertices[ 7], -5.0f, 5.0f,-5.0f, g_dwDiffuseColor, 3.00f, 0.0f, 1.00, 0.0f, 1.00, 0.0f );
  353.     FILL_WALLVERTEX( pVertices[ 8], -5.0f,-5.0f, 5.0f, g_dwDiffuseColor, 4.00f, 1.0f, 0.00, 1.0f, 0.00, 1.0f );
  354.     FILL_WALLVERTEX( pVertices[ 9], -5.0f, 5.0f, 5.0f, g_dwDiffuseColor, 4.00f, 0.0f, 0.00, 0.0f, 0.00, 0.0f );
  355.  
  356.     m_pVBWalls->Unlock();
  357.  
  358.     // Create the floor/ceiling vertex buffer
  359.     if( FAILED( m_pd3dDevice->CreateVertexBuffer( FLOORCEILING_VERT_NUM * sizeof(FLOORCEILINGVERTEX),
  360.         0, D3DFVF_FLOORCEILINGVERTEX, D3DPOOL_MANAGED, &m_pVBFloorCeiling ) ) )
  361.     {
  362.         return E_FAIL;
  363.     }
  364.  
  365.     FLOORCEILINGVERTEX* pFloorVertices;
  366.     m_pVBFloorCeiling->Lock( 0, 0, (BYTE**)&pFloorVertices, 0 );
  367.     FILL_FLOORCEILINGVERTEX( pFloorVertices[0],  -5,-5, 5, 0, 1, 0, 0.0f, 0.0f );
  368.     FILL_FLOORCEILINGVERTEX( pFloorVertices[1],   5,-5, 5, 0, 1, 0, 0.0f, 1.0f );
  369.     FILL_FLOORCEILINGVERTEX( pFloorVertices[2],   5,-5,-5, 0, 1, 0, 1.0f, 1.0f );
  370.     FILL_FLOORCEILINGVERTEX( pFloorVertices[3],   5,-5,-5, 0, 1, 0, 1.0f, 1.0f );
  371.     FILL_FLOORCEILINGVERTEX( pFloorVertices[4],  -5,-5,-5, 0, 1, 0, 1.0f, 0.0f );
  372.     FILL_FLOORCEILINGVERTEX( pFloorVertices[5],  -5,-5, 5, 0, 1, 0, 0.0f, 0.0f );
  373.     FILL_FLOORCEILINGVERTEX( pFloorVertices[6],   5, 5,-5, 0,-1, 0, 1.0f, 1.0f );
  374.     FILL_FLOORCEILINGVERTEX( pFloorVertices[7],   5, 5, 5, 0,-1, 0, 0.0f, 1.0f );
  375.     FILL_FLOORCEILINGVERTEX( pFloorVertices[8],  -5, 5, 5, 0,-1, 0, 0.0f, 0.0f );
  376.     FILL_FLOORCEILINGVERTEX( pFloorVertices[9],  -5, 5, 5, 0,-1, 0, 0.0f, 0.0f );
  377.     FILL_FLOORCEILINGVERTEX( pFloorVertices[10], -5, 5,-5, 0,-1, 0, 1.0f, 0.0f );
  378.     FILL_FLOORCEILINGVERTEX( pFloorVertices[11],  5, 5,-5, 0,-1, 0, 1.0f, 1.0f );
  379.     m_pVBFloorCeiling->Unlock();
  380.  
  381.     // Create some textures
  382.     if( FAILED( D3DUtil_CreateTexture( m_pd3dDevice, _T("floor.bmp"), &g_pFloorTexture ) ) )
  383.         return E_FAIL;
  384.     if( FAILED( D3DUtil_CreateTexture( m_pd3dDevice, g_strTexture0, &g_pTexture0 ) ) )
  385.         return E_FAIL;
  386.     if( FAILED( D3DUtil_CreateTexture( m_pd3dDevice, g_strTexture1, &g_pTexture1 ) ) )
  387.         return E_FAIL;
  388.     if( FAILED( D3DUtil_CreateTexture( m_pd3dDevice, g_strTexture2, &g_pTexture2 ) ) )
  389.         return E_FAIL;
  390.  
  391.     g_dwMaxTextureBlendStages = m_d3dCaps.MaxTextureBlendStages;
  392.  
  393.     return S_OK;
  394. }
  395.  
  396.  
  397.  
  398.  
  399. //-----------------------------------------------------------------------------
  400. // Name: RestoreDeviceObjects()
  401. // Desc: Initialize scene objects.
  402. //-----------------------------------------------------------------------------
  403. HRESULT CAppForm::RestoreDeviceObjects()
  404. {
  405.     m_pFont->RestoreDeviceObjects();
  406.  
  407.     // Create and set up the shine materials w/ textures
  408.     D3DMATERIAL8 mtrl;
  409.     D3DUtil_InitMaterial( mtrl, 1.0f, 1.0f, 1.0f );
  410.     m_pd3dDevice->SetMaterial( &mtrl );
  411.  
  412.     // Set the transform matrices
  413.     D3DXMATRIX matWorld, matView, matProj;
  414.     D3DXVECTOR3 vEyePt    = D3DXVECTOR3( 0.0f, 0.0f, -4.0f );
  415.     D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f,  0.0f );
  416.     D3DXVECTOR3 vUpVec    = D3DXVECTOR3( 0.0f, 1.0f,  0.0f );
  417.  
  418.     D3DXMatrixIdentity( &matWorld );
  419.     D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
  420.     D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/2, 1.0f, 1.0f, 1000.0f );
  421.  
  422.     m_pd3dDevice->SetTransform( D3DTS_WORLD,      &matWorld );
  423.     m_pd3dDevice->SetTransform( D3DTS_VIEW,       &matView );
  424.     m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
  425.  
  426.     // Set any appropiate state
  427.     m_pd3dDevice->SetRenderState( D3DRS_ZENABLE,  TRUE );
  428.     m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
  429.  
  430.     return S_OK;
  431. }
  432.  
  433.  
  434.  
  435.  
  436. //-----------------------------------------------------------------------------
  437. // Name: InvalidateDeviceObjects()
  438. // Desc: Called when the device-dependent objects are about to be lost.
  439. //-----------------------------------------------------------------------------
  440. HRESULT CAppForm::InvalidateDeviceObjects()
  441. {
  442.     m_pFont->InvalidateDeviceObjects();
  443.     return S_OK;
  444. }
  445.  
  446.  
  447.  
  448.  
  449. //-----------------------------------------------------------------------------
  450. // Name: DeleteDeviceObjects()
  451. // Desc: Called when the app is exiting, or the device is being changed,
  452. //       this function deletes any device dependent objects.
  453. //-----------------------------------------------------------------------------
  454. HRESULT CAppForm::DeleteDeviceObjects()
  455. {
  456.     m_pFont->DeleteDeviceObjects();
  457.     SAFE_RELEASE( m_pVBWalls );
  458.     SAFE_RELEASE( m_pVBFloorCeiling );
  459.     SAFE_RELEASE( g_pFloorTexture );
  460.     SAFE_RELEASE( g_pTexture0 );
  461.     SAFE_RELEASE( g_pTexture1 );
  462.     SAFE_RELEASE( g_pTexture2 );
  463.  
  464.     return S_OK;
  465. }
  466.  
  467.  
  468.  
  469.  
  470. //-----------------------------------------------------------------------------
  471. // Name: FinalCleanup()
  472. // Desc: Called before the app exits, this function gives the app the chance
  473. //       to cleanup after itself.
  474. //-----------------------------------------------------------------------------
  475. HRESULT CAppForm::FinalCleanup()
  476. {
  477.     SAFE_DELETE( m_pFont );
  478.     return S_OK;
  479. }
  480.  
  481.  
  482.  
  483.  
  484. //-----------------------------------------------------------------------------
  485. // Name: ConfirmDevice()
  486. // Desc: Called during device intialization, this code checks the device
  487. //       for some minimum set of capabilities
  488. //-----------------------------------------------------------------------------
  489. HRESULT CAppForm::ConfirmDevice( D3DCAPS8* pCaps, DWORD dwBehavior, 
  490.                                  D3DFORMAT Format )
  491. {
  492.     return S_OK;
  493. }
  494.  
  495.  
  496.  
  497.  
  498. //-----------------------------------------------------------------------------
  499. // Name: SetTextureMaps()
  500. // Desc: Changes the texture maps used during rendering of the room.
  501. //-----------------------------------------------------------------------------
  502. VOID CAppForm::SetTextureMaps( const TCHAR* strTexture0, const TCHAR* strTexture1,
  503.                          const TCHAR* strTexture2 )
  504. {
  505.     _tcscpy( g_strTexture0, strTexture0 );
  506.     _tcscpy( g_strTexture1, strTexture1 );
  507.     _tcscpy( g_strTexture2, strTexture2 );
  508.  
  509.     g_bTexturesChanged = TRUE;
  510. }
  511.  
  512.  
  513.  
  514.  
  515.