0001: // ----------------------------------------------------------------------------
0002: //
0003: // draw.cpp - 描画部分
0004: // 
0005: // Copyright (c) 2001 if (if@edokko.com)
0006: // All Rights Reserved.
0007: //
0008: // ----------------------------------------------------------------------------
0009: #define STRICT
0010: 
0011: #include <windows.h>
0012: #include "main.h"
0013: #include "draw.h"
0014: #include "load.h"
0015: 
0016: static const int SHADOWMAP_HEIGHT = 512;
0017: static const int SHADOWMAP_WIDTH = 512;
0018: 
0019: LPDIRECT3DVERTEXBUFFER8 pMeshVB = NULL;
0020: LPDIRECT3DINDEXBUFFER8  pMeshIndex = NULL;
0021: D3DXATTRIBUTERANGE      *pSubsetTable = NULL;
0022: DWORD                   nMeshFaces = 0;
0023: DWORD                   nMeshVertices = 0;
0024: D3DMATERIAL8            *pMeshMaterials = NULL;     // メッシュの質感
0025: LPDIRECT3DTEXTURE8      *pMeshTextures  = NULL;     // メッシュのテクスチャー
0026: DWORD                   dwNumMaterials = 0L;        // マテリアルの数
0027: FLOAT                   MeshRadius;                 // メッシュの大きさ
0028: 
0029: DWORD                   hVertexShader=~0;           // モデルの描画
0030: DWORD                   hPixelShader=~0;            // モデルの描画
0031: LPDIRECT3DCUBETEXTURE8  pCubeMap=NULL;
0032: 
0033: 
0034: // 影を作りながら描画
0035: LPDIRECT3DSURFACE8      pBackbuffer = NULL;
0036: LPDIRECT3DSURFACE8      lpZbuffer = NULL;
0037: LPDIRECT3DTEXTURE8      pMaskTexture = NULL;        // マスク用テクスチャー
0038: LPDIRECT3DVERTEXBUFFER8 pBlurVB = NULL;
0039: LPDIRECT3DINDEXBUFFER8  pBlurIB = NULL;
0040: 
0041: LPDIRECT3DTEXTURE8      pTextureCol;
0042: LPDIRECT3DSURFACE8      pTextureSurfaceCol;
0043: LPDIRECT3DTEXTURE8      pTextureZ[2];
0044: LPDIRECT3DSURFACE8      pTextureSurfaceZ[2];
0045: LPDIRECT3DTEXTURE8      pTextureShadow;
0046: LPDIRECT3DSURFACE8      pTextureSurfaceShadow;
0047: LPDIRECT3DTEXTURE8      pTextureShadowZ;
0048: LPDIRECT3DSURFACE8      pTextureSurfaceShadowZ;
0049: 
0050: typedef struct {
0051:     float x,y,z;
0052:     float tu,tv;
0053: }D3D_BLUR_VERTEX;
0054: #define D3DFVF_BLUR_VERTEX      (D3DFVF_XYZ | D3DFVF_TEX1)
0055: 
0056: DWORD dwBlurDecl[] = {
0057:     D3DVSD_STREAM(0),
0058:     D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3 ),          //D3DVSDE_POSITION,  0
0059:     D3DVSD_REG(D3DVSDE_TEXCOORD0,D3DVSDT_FLOAT2 ),          //D3DVSDE_TEXCOORD0, 7  
0060:     D3DVSD_END()
0061: };
0062: 
0063: 
0064: // ----------------------------------------------------------------------------
0065: // 外部関数
0066: void InitBg ( LPDIRECT3DDEVICE8 lpD3DDev );
0067: void DrawBg ( LPDIRECT3DDEVICE8 lpD3DDev );
0068: void CleanBg( LPDIRECT3DDEVICE8 lpD3DDev );
0069: 
0070: 
0071: 
0072: // ----------------------------------------------------------------------------
0073: // Name: LoadXFile(char* filename, LPDIRECT3DDEVICE8 lpD3DDev)
0074: // Desc: X-Fileの読み込み
0075: //-----------------------------------------------------------------------------
0076: HRESULT LoadXFile(char* filename, LPDIRECT3DDEVICE8 lpD3DDev)
0077: {
0078:     LPD3DXMESH pMesh, pMeshOpt;
0079:     LPD3DXBUFFER pD3DXMtrlBuffer = NULL;
0080:     DWORD i;
0081:     HRESULT hr;
0082: 
0083:     hr = D3DXLoadMeshFromX(filename, D3DXMESH_MANAGED,
0084:                                 lpD3DDev, NULL,
0085:                                 &pD3DXMtrlBuffer, &dwNumMaterials,
0086:                                 &pMesh);
0087:     if(FAILED(hr)) return E_FAIL;
0088: 
0089:     //並び替えておく
0090:     pMesh->Optimize(D3DXMESHOPT_ATTRSORT, NULL, NULL, NULL, NULL, &pMeshOpt);
0091:     RELEASE(pMesh);
0092: 
0093:     //アトリビュートテーブル
0094:     pMeshOpt->GetAttributeTable(NULL,&dwNumMaterials);
0095:     pSubsetTable = new D3DXATTRIBUTERANGE[dwNumMaterials];
0096:     pMeshOpt->GetAttributeTable(pSubsetTable, &dwNumMaterials);
0097: 
0098:     // FVF変換
0099:     hr = pMeshOpt->CloneMeshFVF(pMeshOpt->GetOptions(), D3DFVF_VERTEX, lpD3DDev, &pMesh);
0100:     if(FAILED(hr)) return E_FAIL;
0101:     RELEASE(pMeshOpt);
0102:     D3DXComputeNormals(pMesh, NULL);
0103: 
0104:     //Vertex Bufferにコピーする
0105:     D3DVERTEX* pSrc;
0106:     D3D_CUSTOMVERTEX* pDest;
0107:     LPDIRECT3DINDEXBUFFER8 pSrcIndex;
0108:     WORD* pISrc;
0109:     WORD* pIDest;
0110: 
0111:     DWORD nMeshVertices = pMesh->GetNumVertices();
0112:     DWORD nMeshFaces = pMesh->GetNumFaces();
0113:     lpD3DDev->CreateVertexBuffer(nMeshVertices * sizeof(D3D_CUSTOMVERTEX),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED,&pMeshVB);
0114:     lpD3DDev->CreateIndexBuffer(nMeshFaces * 3 * sizeof(WORD),0,D3DFMT_INDEX16,D3DPOOL_MANAGED,&pMeshIndex);
0115: 
0116:     LPDIRECT3DVERTEXBUFFER8 pVB;
0117:     pMesh->GetVertexBuffer(&pVB);
0118:     pVB->Lock(0,0,(BYTE**)&pSrc,0);
0119:     pMeshVB->Lock(0,0,(BYTE**)&pDest,0);
0120:     MeshRadius = 0.0f;
0121:     for(i=0;i<nMeshVertices;i++){
0122:         pDest->x = pSrc->x;
0123:         pDest->y = pSrc->y;
0124:         pDest->z = pSrc->z;
0125:         pDest->nx = pSrc->nx;
0126:         pDest->ny = pSrc->ny;
0127:         pDest->nz = pSrc->nz;
0128:         pDest->tu0 = pSrc->tu0;
0129:         pDest->tu0 = pSrc->tu0;
0130:         // サイズの計算
0131:         FLOAT radius = sqrtf( pSrc->x*pSrc->x + pSrc->y*pSrc->y + pSrc->z*pSrc->z );
0132:         if (MeshRadius < radius) MeshRadius = radius;
0133:         
0134:         pSrc += 1;
0135:         pDest += 1;
0136:     }
0137:     pVB->Unlock();
0138:     pVB->Release();
0139:     pMeshVB->Unlock();
0140: 
0141:     //インデックスのコピー
0142:     pMesh->GetIndexBuffer(&pSrcIndex);
0143:     pSrcIndex->Lock(0,0,(BYTE**)&pISrc,0);
0144:     pMeshIndex->Lock(0,0,(BYTE**)&pIDest,0);
0145:     CopyMemory(pIDest,pISrc,nMeshFaces * 3 * sizeof(WORD));
0146:     pSrcIndex->Unlock();
0147:     pMeshIndex->Unlock();
0148:     pSrcIndex->Release();
0149: 
0150:     // pD3DXMtrlBuffer から、質感やテクスチャーの情報を読み取る
0151:     D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
0152:     pMeshTextures = new LPDIRECT3DTEXTURE8[dwNumMaterials];
0153:     pMeshMaterials = new D3DMATERIAL8[dwNumMaterials];
0154: 
0155:     for(i = 0; i < dwNumMaterials; i++){
0156:         pMeshMaterials[i] = d3dxMaterials[i].MatD3D;
0157:         pMeshMaterials[i].Ambient = pMeshMaterials[i].Diffuse;
0158:         hr = D3DXCreateTextureFromFile( lpD3DDev, 
0159:                                         d3dxMaterials[i].pTextureFilename, 
0160:                                         &pMeshTextures[i] );
0161:         if(FAILED(hr)) pMeshTextures[i] = NULL;
0162:     }
0163:     RELEASE(pD3DXMtrlBuffer);
0164:     
0165:     RELEASE(pMesh);
0166: 
0167:     return S_OK;
0168: }
0169: //-----------------------------------------------------------------------------
0170: // Name: InitRenderTexture()
0171: // Desc: レンダリングテクスチャー用の下準備
0172: //-----------------------------------------------------------------------------
0173: HRESULT InitRenderTexture(LPDIRECT3DDEVICE8 lpD3DDev)
0174: {
0175:     HRESULT hr;
0176:     DWORD i;
0177:     
0178:     // 頂点バッファの作成 
0179:     D3D_BLUR_VERTEX *pBlurDest;
0180:     WORD *pIndex;
0181:     lpD3DDev->CreateVertexBuffer( 4 * sizeof(D3D_BLUR_VERTEX),
0182:                                 D3DUSAGE_WRITEONLY, D3DFVF_BLUR_VERTEX, D3DPOOL_MANAGED,
0183:                                 &pBlurVB );
0184:     // 頂点をセットアップ
0185:     pBlurVB->Lock ( 0, 0, (BYTE**)&pBlurDest, 0 );
0186:     for (i = 0; i < 4; i++) {
0187:         pBlurDest->x   = (i == 0 || i == 1)?-1:(float)1;
0188:         pBlurDest->y   = (i == 0 || i == 2)?-1:(float)1;
0189:         pBlurDest->z   = 0.0f;
0190:         pBlurDest->tu = (i == 2 || i == 3)?1:(float)0;
0191:         pBlurDest->tv = (i == 0 || i == 2)?1:(float)0;
0192:         pBlurDest++;
0193:     }       
0194:     pBlurVB->Unlock ();
0195:     // インデックスをセットアップ
0196:     lpD3DDev->CreateIndexBuffer( 6 * sizeof(WORD),
0197:                                0,
0198:                                D3DFMT_INDEX16, D3DPOOL_MANAGED,
0199:                                &pBlurIB );
0200:     pBlurIB->Lock ( 0, 0, (BYTE**)&pIndex, 0 );
0201:     pIndex[0] = 0;  pIndex[1] = 1;  pIndex[2] = 2;
0202:     pIndex[3] = 1;  pIndex[4] = 3;  pIndex[5] = 2;
0203:     pBlurIB->Unlock ();
0204: 
0205:     return S_OK;
0206: }
0207: //-----------------------------------------------------------------------------
0208: // 
0209: //-----------------------------------------------------------------------------
0210: void make_normalize_cubemap( D3DXVECTOR4 *pOut, D3DXVECTOR3 *pTexCoord,
0211: D3DXVECTOR3 *pTexelSize, LPVOID pData)
0212: {
0213:     D3DXVECTOR3 n;
0214:     D3DXVec3Normalize( &n, pTexCoord );
0215: 
0216:     pOut->x = 0.5f*(n.x + 1.0f);
0217:     pOut->y = 0.5f*(n.y + 1.0f);
0218:     pOut->z = 0.5f*(n.z + 1.0f);
0219:     pOut->w = 1.0f;
0220: }
0221: //-----------------------------------------------------------------------------
0222: // Name: InitRender()
0223: // Desc: Load the mesh and build the material and texture arrays
0224: //-----------------------------------------------------------------------------
0225: HRESULT InitRender(LPDIRECT3DDEVICE8 lpD3DDev)
0226: {
0227:     HRESULT hr;
0228: 
0229:     // モデルの読み込み
0230:     if ( FAILED(hr = LoadXFile("nsx.x", lpD3DDev)) ) return hr;
0231:     
0232:     // マスク用テクスチャーの読み込み
0233:     if ( FAILED(CTextureMgr::Load(lpD3DDev, "mask.bmp",     &pMaskTexture)) ) return hr;
0234:     
0235:     // シェ-ダーのロード
0236:     if ( FAILED(CVertexShaderMgr::Load(lpD3DDev, "vs.vsh",     &hVertexShader, dwDecl)) ) return hr;
0237:     if ( FAILED( CPixelShaderMgr::Load(lpD3DDev, "ps.psh",      &hPixelShader)) ) return hr;
0238:     
0239:     // レンダリングテクスチャー用の初期化
0240:     InitRenderTexture(lpD3DDev);
0241:     
0242:     // 正規化キューブマップの作成
0243:     hr = lpD3DDev->CreateCubeTexture( 512, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
0244:                                 D3DPOOL_DEFAULT , &pCubeMap );
0245:     if ( FAILED(hr) ) return hr;
0246:     hr = D3DXFillCubeTexture( pCubeMap, make_normalize_cubemap, NULL );
0247:     if ( FAILED(hr) ) return hr;
0248: 
0249:     // 背景部分の初期化
0250:     InitBg(lpD3DDev);
0251: 
0252:     // 不変なレジスタの設定
0253:     lpD3DDev->SetRenderState( D3DRS_ZENABLE, TRUE );
0254:     lpD3DDev->SetRenderState( D3DRS_LIGHTING,  FALSE );
0255:     lpD3DDev->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE);
0256:     lpD3DDev->SetVertexShaderConstant(12, &D3DXVECTOR4(0.0f, 0.5f, 1.0f, 2.0f), 1);
0257: 
0258:     lpD3DDev->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
0259:     lpD3DDev->SetTextureStageState(1, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
0260:     lpD3DDev->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
0261:     lpD3DDev->SetTextureStageState(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
0262:     lpD3DDev->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_NONE);
0263:     lpD3DDev->SetTextureStageState(1, D3DTSS_MIPFILTER, D3DTEXF_NONE);
0264:     lpD3DDev->SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
0265:     lpD3DDev->SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
0266:     lpD3DDev->SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
0267:     lpD3DDev->SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
0268: 
0269:     return S_OK;
0270: }
0271: //-----------------------------------------------------------------------------
0272: // Name: Render()
0273: // Desc: Draws the scene
0274: //-----------------------------------------------------------------------------
0275: const float z_min =   1.0f;
0276: const float z_max  = 70.0f;
0277: D3DXVECTOR4 lightDir(1.0f, 1.0f, 0.0, 0.0f);
0278: 
0279: VOID DrawModel( LPDIRECT3DDEVICE8 lpD3DDev )
0280: {
0281:     D3DXMATRIX mVP,  mWorld, mView,  mProj, mTex;
0282:     D3DXMATRIX mVPL, mLight, mViewL, mProjL;
0283:     D3DXMATRIX  m;
0284:     D3DXVECTOR4 vl;
0285:     DWORD i;
0286:     
0287:     D3DXVec4Normalize(&vl, &lightDir);
0288:     lpD3DDev->SetVertexShaderConstant(11, &vl, 1);
0289: 
0290:     // 
0291:     // 通常レンダリング用の行列を作成
0292:     // 
0293:     // ビュー行列
0294:     D3DXVECTOR3 eye    = D3DXVECTOR3(0.0f,1.4f*MeshRadius,2.5f*MeshRadius);
0295:     D3DXVECTOR3 lookAt = D3DXVECTOR3(0.0f,  0.0f,  0.0f);
0296:     D3DXVECTOR3 up     = D3DXVECTOR3(0.0f,  1.0f,  0.0f);
0297:     D3DXMatrixLookAtLH(&mView, &eye, &lookAt, &up);
0298:     // 射影行列
0299:     D3DXMatrixPerspectiveFovLH(&mProj
0300:         , D3DXToRadian(60.0f)                       // 視野角
0301:         , (float)WIDTH/(float)HEIGHT                // アスペクト比
0302:         , z_min, z_max                              // 最近接距離,最遠方距離
0303:         );
0304:     
0305:     mVP = mView * mProj;
0306:     lpD3DDev->SetVertexShaderConstant( 15, &eye, 1);
0307: 
0308:     //
0309:     // 外側もでる描画
0310:     //
0311:     float t = 0.0001f*(timeGetTime()%10000);
0312:     D3DXMatrixTranslation(&m, 1.5f*MeshRadius, 0,0);
0313:     D3DXMatrixRotationY( &mWorld, 3.0f*2.0f*D3DX_PI*t );
0314: //D3DXMatrixRotationY( &mWorld, -0.2*PI/2 ); // 撮影角度
0315:     mWorld = m * mWorld;
0316:     
0317:     m = mWorld * mVP;
0318:     lpD3DDev->SetVertexShaderConstant( 0,D3DXMatrixTranspose(&m,&m), 4);
0319:     lpD3DDev->SetVertexShaderConstant( 4,D3DXMatrixTranspose(&m,&mWorld), 4);
0320: 
0321:     D3DXMatrixInverse( &m,  NULL, &mWorld);
0322:     D3DXVec4Transform(&vl, &lightDir, &m);
0323:     D3DXVec4Normalize(&vl, &vl);
0324:     vl.w = 0.3f;
0325:     lpD3DDev->SetVertexShaderConstant(13, &vl, 1);
0326:     
0327:     lpD3DDev->SetStreamSource(0, pMeshVB, sizeof(D3D_CUSTOMVERTEX));
0328:     lpD3DDev->SetIndices(pMeshIndex,0);
0329:     
0330:     for(i=0;i<dwNumMaterials;i++){
0331:         //色をセット
0332:         D3DXVECTOR4 vl;
0333:         vl.x = pMeshMaterials[i].Diffuse.r;
0334:         vl.y = pMeshMaterials[i].Diffuse.g;
0335:         vl.z = pMeshMaterials[i].Diffuse.b;
0336:         lpD3DDev->SetVertexShaderConstant(14, &vl, 1);
0337: 
0338:         lpD3DDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 
0339:                                         pSubsetTable[i].VertexStart,
0340:                                         pSubsetTable[i].VertexCount,
0341:                                         pSubsetTable[i].FaceStart * 3,
0342:                                         pSubsetTable[i].FaceCount);
0343:     }
0344:     //
0345:     // 内側モデル
0346:     //
0347:     D3DXMatrixRotationY( &mWorld, -1.0f*2.0f*D3DX_PI*t );
0348: //D3DXMatrixRotationY( &mWorld,-1.10f*PI/2 ); // 撮影角度
0349: 
0350:     m = mWorld * mVP;
0351:     lpD3DDev->SetVertexShaderConstant( 0,D3DXMatrixTranspose(&m,&m), 4);
0352:     lpD3DDev->SetVertexShaderConstant( 4,D3DXMatrixTranspose(&m,&mWorld), 4);
0353: 
0354:     D3DXMatrixInverse( &m,  NULL, &mWorld);
0355:     D3DXVec4Transform(&vl, &lightDir, &m);
0356:     D3DXVec4Normalize(&vl, &vl);
0357:     lpD3DDev->SetVertexShaderConstant(13, &vl, 1);
0358:     
0359:     for(i=0;i<dwNumMaterials;i++){
0360:         //色をセット
0361:         D3DXVECTOR4 vl;
0362:         vl.x = pMeshMaterials[i].Diffuse.r;
0363:         vl.y = pMeshMaterials[i].Diffuse.g;
0364:         vl.z = pMeshMaterials[i].Diffuse.b;
0365:         lpD3DDev->SetVertexShaderConstant(14, &vl, 1);
0366: 
0367:         lpD3DDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 
0368:                                         pSubsetTable[i].VertexStart,
0369:                                         pSubsetTable[i].VertexCount,
0370:                                         pSubsetTable[i].FaceStart * 3,
0371:                                         pSubsetTable[i].FaceCount);
0372:     }
0373: 
0374:     //
0375:     // 背景描画
0376:     // 
0377:     D3DXMatrixScaling(&mWorld, 3.0f, 3.0f, 3.0f);
0378:     lpD3DDev->SetTransform(D3DTS_WORLD, &mWorld);
0379:     lpD3DDev->SetTransform(D3DTS_VIEW,  &mView);
0380:     lpD3DDev->SetTransform(D3DTS_PROJECTION, &mProj);
0381:     lpD3DDev->SetTexture( 1, NULL );
0382:     lpD3DDev->SetPixelShader (  0 );
0383: 
0384:     DrawBg(lpD3DDev);
0385: }
0386: //-----------------------------------------------------------------------------
0387: // Name: Render()
0388: // Desc: Draws the scene
0389: //-----------------------------------------------------------------------------
0390: VOID Render(LPDIRECT3DDEVICE8 lpD3DDev)
0391: {
0392:     // ------------------------------------------------------------------------
0393:     // シーンの作成
0394:     // ------------------------------------------------------------------------
0395:     lpD3DDev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x008000, 1.0f, 0L);
0396: 
0397:     lpD3DDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
0398:     lpD3DDev->SetTextureStageState(0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1);
0399:     lpD3DDev->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
0400:     lpD3DDev->SetTextureStageState(1, D3DTSS_COLOROP,   D3DTOP_SELECTARG1);
0401:     lpD3DDev->SetVertexShader( hVertexShader );
0402:     lpD3DDev->SetPixelShader (  hPixelShader );
0403:     lpD3DDev->SetTexture( 0, pCubeMap );
0404:     lpD3DDev->SetTexture( 1, pCubeMap );
0405:     DrawModel(lpD3DDev );
0406:     
0407:     // 他でレンダリングしても問題が出ない設定にする
0408:     lpD3DDev->SetTexture( 0, NULL );
0409:     lpD3DDev->SetTexture( 1, NULL );
0410:     lpD3DDev->SetPixelShader(0);
0411: #if 1
0412:     //-----------------------------------------------------------------------------
0413:     // デバッグ用、適当にテクスチャーを表示する
0414:     //-----------------------------------------------------------------------------
0415:     for(int i=0;i<6;i++){
0416:         struct TLVERTEX {
0417:             float x,y,z,rhw;
0418:             float tu,tv,tr;
0419:         };
0420:         #define FVF_TLVERTEX (D3DFVF_XYZRHW | D3DFVF_TEX1)
0421: 
0422:         lpD3DDev->SetTextureStageState(0,D3DTSS_COLOROP,    D3DTOP_SELECTARG1);
0423:         lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG1,  D3DTA_TEXTURE);
0424:         lpD3DDev->SetTextureStageState(1,D3DTSS_COLOROP,    D3DTOP_DISABLE);
0425:         float scale = 64.0f;
0426:         TLVERTEX Vertex[6][4] = {
0427:             {
0428:                 //   x     y     z rhw tu tv tr
0429:                 {0*scale,1*scale,0, 1, -1, 1,-1,},
0430:                 {1*scale,1*scale,0, 1, -1, 1, 1,},
0431:                 {0*scale,2*scale,0, 1, -1,-1,-1,},
0432:                 {1*scale,2*scale,0, 1, -1,-1, 1,},
0433:             },{
0434:                 //   x     y     z rhw tu tv tr
0435:                 {1*scale,1*scale,0, 1, -1, 1, 1,},
0436:                 {2*scale,1*scale,0, 1,  1, 1, 1,},
0437:                 {1*scale,2*scale,0, 1, -1,-1, 1,},
0438:                 {2*scale,2*scale,0, 1,  1,-1, 1,},
0439:             },{
0440:                 //   x     y     z rhw tu tv tr
0441:                 {2*scale,1*scale,0, 1,  1, 1, 1,},
0442:                 {3*scale,1*scale,0, 1,  1, 1,-1,},
0443:                 {2*scale,2*scale,0, 1,  1,-1, 1,},
0444:                 {3*scale,2*scale,0, 1,  1,-1,-1,},
0445:             },{
0446:                 //   x     y     z rhw tu tv tr
0447:                 {3*scale,1*scale,0, 1,  1, 1,-1,},
0448:                 {4*scale,1*scale,0, 1, -1, 1,-1,},
0449:                 {3*scale,2*scale,0, 1,  1,-1,-1,},
0450:                 {4*scale,2*scale,0, 1, -1,-1,-1,},
0451:             },{
0452:                 //   x     y     z rhw tu tv tr
0453:                 {1*scale,0*scale,0, 1, -1, 1,-1,},
0454:                 {2*scale,0*scale,0, 1,  1, 1,-1,},
0455:                 {1*scale,1*scale,0, 1, -1, 1, 1,},
0456:                 {2*scale,1*scale,0, 1,  1, 1, 1,},
0457:             },{
0458:                 //   x     y     z rhw tu tv tr
0459:                 {1*scale,2*scale,0, 1, -1,-1, 1,},
0460:                 {2*scale,2*scale,0, 1,  1,-1, 1,},
0461:                 {1*scale,3*scale,0, 1, -1,-1,-1,},
0462:                 {2*scale,3*scale,0, 1,  1,-1,-1,},
0463:             },
0464:         };
0465:         lpD3DDev->SetTexture( 0, pCubeMap );
0466:         lpD3DDev->SetVertexShader( FVF_TLVERTEX | D3DFVF_TEXCOORDSIZE3(0) );
0467:         lpD3DDev->SetPixelShader(0);
0468:         lpD3DDev->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, Vertex[i], sizeof( TLVERTEX ) );
0469:     }
0470: #endif
0471: }
0472: //-----------------------------------------------------------------------------
0473: // メッシュオブジェクト削除
0474: //-----------------------------------------------------------------------------
0475: void DeleteMeshObject(void)
0476: {
0477:     DWORD i;
0478: 
0479:     if(pMeshVB == NULL) return;
0480: 
0481:     for(i=0; i<dwNumMaterials; i++){
0482:         RELEASE(pMeshTextures[i]);
0483:     }
0484:     delete[] pMeshTextures;
0485:     delete[] pMeshMaterials;
0486:     delete[] pSubsetTable;
0487: 
0488:     RELEASE(pMeshVB);
0489:     RELEASE(pMeshIndex);
0490: }
0491: //-----------------------------------------------------------------------------
0492: // Name: CleanRender()
0493: // Desc: 後始末
0494: //-----------------------------------------------------------------------------
0495: void CleanRender(LPDIRECT3DDEVICE8 lpD3DDev)
0496: {
0497:     DWORD i;
0498: 
0499:     CleanBg(lpD3DDev);
0500:     
0501:     for(i=0;i<2;i++){
0502:         RELEASE(pTextureSurfaceZ[i]);
0503:         RELEASE(pTextureZ[i]);
0504:     }
0505:     RELEASE(pTextureSurfaceCol);
0506:     RELEASE(pTextureCol);
0507:     RELEASE(pTextureSurfaceShadowZ);
0508:     RELEASE(pTextureShadowZ);
0509:     RELEASE(pTextureSurfaceShadow);
0510:     RELEASE(pTextureShadow);
0511:     
0512:     RELEASE(pBackbuffer);
0513:     
0514:     CPixelShaderMgr::Release(lpD3DDev, &hPixelShader);
0515:     CVertexShaderMgr::Release(lpD3DDev, &hVertexShader);
0516:     
0517:     RELEASE(pMaskTexture);
0518:     DeleteMeshObject();
0519: }
0520: