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