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: #define RENDER_CAR0 (1<<0) 0017: #define RENDER_CAR1 (1<<1) 0018: #define RENDER_BG (1<<2) 0019: 0020: static const int SHADOWMAP_HEIGHT = 512; 0021: static const int SHADOWMAP_WIDTH = 512; 0022: 0023: LPDIRECT3DVERTEXBUFFER8 pMeshVB = NULL; 0024: LPDIRECT3DINDEXBUFFER8 pMeshIndex = NULL; 0025: D3DXATTRIBUTERANGE *pSubsetTable = NULL; 0026: DWORD nMeshFaces = 0; 0027: DWORD nMeshVertices = 0; 0028: D3DMATERIAL8 *pMeshMaterials = NULL; // メッシュの質感 0029: LPDIRECT3DTEXTURE8 *pMeshTextures = NULL; // メッシュのテクスチャー 0030: DWORD dwNumMaterials = 0L; // マテリアルの数 0031: FLOAT MeshRadius; // メッシュの大きさ 0032: 0033: DWORD hVertexShader=~0; // モデルの描画 0034: DWORD hPixelShader=~0; // モデルの描画 0035: DWORD hVertexShaderFish=~0; // モデルの描画 0036: DWORD hPixelShaderFish=~0; // モデルの描画 0037: DWORD hVertexShaderDPEM=~0; // モデルの描画 0038: DWORD hPixelShaderDPEM=~0; // モデルの描画 0039: 0040: LPDIRECT3DTEXTURE8 pTexture0[2]; 0041: LPDIRECT3DTEXTURE8 pTexture1[2]; 0042: LPDIRECT3DSURFACE8 pTextureSurface0[2]; 0043: LPDIRECT3DSURFACE8 pTextureSurface1[2]; 0044: LPDIRECT3DSURFACE8 pBackbuffer = NULL; 0045: LPDIRECT3DSURFACE8 lpZbuffer = NULL; 0046: 0047: // ---------------------------------------------------------------------------- 0048: // 外部関数 0049: void InitBg(LPDIRECT3DDEVICE8 lpD3DDev); 0050: void DrawBg(LPDIRECT3DDEVICE8 lpD3DDev); 0051: void CleanBg(LPDIRECT3DDEVICE8 lpD3DDev); 0052: 0053: 0054: 0055: // ---------------------------------------------------------------------------- 0056: // Name: LoadXFile(char* filename, LPDIRECT3DDEVICE8 lpD3DDev) 0057: // Desc: X-Fileの読み込み 0058: //----------------------------------------------------------------------------- 0059: HRESULT LoadXFile(char* filename, LPDIRECT3DDEVICE8 lpD3DDev) 0060: { 0061: LPD3DXMESH pMesh, pMeshOpt; 0062: LPD3DXBUFFER pD3DXMtrlBuffer = NULL; 0063: DWORD i; 0064: HRESULT hr; 0065: 0066: hr = D3DXLoadMeshFromX(filename, D3DXMESH_MANAGED, 0067: lpD3DDev, NULL, 0068: &pD3DXMtrlBuffer, &dwNumMaterials, 0069: &pMesh); 0070: if(FAILED(hr)) return E_FAIL; 0071: 0072: //並び替えておく 0073: pMesh->Optimize(D3DXMESHOPT_ATTRSORT, NULL, NULL, NULL, NULL, &pMeshOpt); 0074: RELEASE(pMesh); 0075: 0076: //アトリビュートテーブル 0077: pMeshOpt->GetAttributeTable(NULL,&dwNumMaterials); 0078: pSubsetTable = new D3DXATTRIBUTERANGE[dwNumMaterials]; 0079: pMeshOpt->GetAttributeTable(pSubsetTable, &dwNumMaterials); 0080: 0081: // FVF変換 0082: hr = pMeshOpt->CloneMeshFVF(pMeshOpt->GetOptions(), D3DFVF_VERTEX, lpD3DDev, &pMesh); 0083: if(FAILED(hr)) return E_FAIL; 0084: RELEASE(pMeshOpt); 0085: D3DXComputeNormals(pMesh, NULL); 0086: 0087: //Vertex Bufferにコピーする 0088: D3DVERTEX* pSrc; 0089: D3D_CUSTOMVERTEX* pDest; 0090: LPDIRECT3DINDEXBUFFER8 pSrcIndex; 0091: WORD* pISrc; 0092: WORD* pIDest; 0093: 0094: DWORD nMeshVertices = pMesh->GetNumVertices(); 0095: DWORD nMeshFaces = pMesh->GetNumFaces(); 0096: lpD3DDev->CreateVertexBuffer(nMeshVertices * sizeof(D3D_CUSTOMVERTEX),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED,&pMeshVB); 0097: lpD3DDev->CreateIndexBuffer(nMeshFaces * 3 * sizeof(WORD),0,D3DFMT_INDEX16,D3DPOOL_MANAGED,&pMeshIndex); 0098: 0099: LPDIRECT3DVERTEXBUFFER8 pVB; 0100: pMesh->GetVertexBuffer(&pVB); 0101: pVB->Lock(0,0,(BYTE**)&pSrc,0); 0102: pMeshVB->Lock(0,0,(BYTE**)&pDest,0); 0103: MeshRadius = 0.0f; 0104: for(i=0;i<nMeshVertices;i++){ 0105: pDest->x = pSrc->x; 0106: pDest->y = pSrc->y; 0107: pDest->z = pSrc->z; 0108: pDest->nx = pSrc->nx; 0109: pDest->ny = pSrc->ny; 0110: pDest->nz = pSrc->nz; 0111: pDest->tu0 = pSrc->tu0; 0112: pDest->tu0 = pSrc->tu0; 0113: // サイズの計算 0114: FLOAT radius = sqrtf( pSrc->x*pSrc->x + pSrc->y*pSrc->y + pSrc->z*pSrc->z ); 0115: if (MeshRadius < radius) MeshRadius = radius; 0116: 0117: pSrc += 1; 0118: pDest += 1; 0119: } 0120: pVB->Unlock(); 0121: pVB->Release(); 0122: pMeshVB->Unlock(); 0123: 0124: //インデックスのコピー 0125: pMesh->GetIndexBuffer(&pSrcIndex); 0126: pSrcIndex->Lock(0,0,(BYTE**)&pISrc,0); 0127: pMeshIndex->Lock(0,0,(BYTE**)&pIDest,0); 0128: CopyMemory(pIDest,pISrc,nMeshFaces * 3 * sizeof(WORD)); 0129: pSrcIndex->Unlock(); 0130: pMeshIndex->Unlock(); 0131: pSrcIndex->Release(); 0132: 0133: // pD3DXMtrlBuffer から、質感やテクスチャーの情報を読み取る 0134: D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer(); 0135: pMeshTextures = new LPDIRECT3DTEXTURE8[dwNumMaterials]; 0136: pMeshMaterials = new D3DMATERIAL8[dwNumMaterials]; 0137: 0138: for(i = 0; i < dwNumMaterials; i++){ 0139: pMeshMaterials[i] = d3dxMaterials[i].MatD3D; 0140: pMeshMaterials[i].Ambient = pMeshMaterials[i].Diffuse; 0141: hr = D3DXCreateTextureFromFile( lpD3DDev, 0142: d3dxMaterials[i].pTextureFilename, 0143: &pMeshTextures[i] ); 0144: if(FAILED(hr)) pMeshTextures[i] = NULL; 0145: } 0146: RELEASE(pD3DXMtrlBuffer); 0147: 0148: RELEASE(pMesh); 0149: 0150: return S_OK; 0151: } 0152: 0153: //----------------------------------------------------------------------------- 0154: // Name: InitRender() 0155: // Desc: Load the mesh and build the material and texture arrays 0156: //----------------------------------------------------------------------------- 0157: HRESULT InitRender(LPDIRECT3DDEVICE8 lpD3DDev) 0158: { 0159: HRESULT hr; 0160: 0161: // モデルの読み込み 0162: if ( FAILED(hr = LoadXFile("nsx.x", lpD3DDev)) ) return hr; 0163: 0164: // バーテックスシェーダーを作成する 0165: if ( FAILED(CVertexShaderMgr::Load(lpD3DDev, "vs.vsh", &hVertexShader, dwDecl)) ) return hr; 0166: if ( FAILED( CPixelShaderMgr::Load(lpD3DDev, "ps.psh", &hPixelShader)) ) return hr; 0167: if ( FAILED(CVertexShaderMgr::Load(lpD3DDev, "fish.vsh", &hVertexShaderFish, dwDecl)) ) return hr; 0168: if ( FAILED( CPixelShaderMgr::Load(lpD3DDev, "fish.psh", &hPixelShaderFish)) ) return hr; 0169: if ( FAILED(CVertexShaderMgr::Load(lpD3DDev, "dpem.vsh", &hVertexShaderDPEM, dwDecl)) ) return hr; 0170: if ( FAILED( CPixelShaderMgr::Load(lpD3DDev, "dpem.psh", &hPixelShaderDPEM)) ) return hr; 0171: 0172: // 描画用テクスチャーを用意する(2枚分) 0173: if ( FAILED(hr = lpD3DDev->GetRenderTarget(&pBackbuffer))) return hr; 0174: D3DSURFACE_DESC Desc; 0175: if ( FAILED(hr = pBackbuffer->GetDesc( &Desc ))) return hr; 0176: 0177: if( FAILED(hr = lpD3DDev->GetDepthStencilSurface( &lpZbuffer ))) return hr; // 深度バッファのサーフェスを確保する 0178: for( int i = 0; i < 2; i++ ){ 0179: if( FAILED(hr = lpD3DDev->CreateTexture(WIDTH,HEIGHT, 1 ,D3DUSAGE_RENDERTARGET, Desc.Format, D3DPOOL_DEFAULT, &pTexture0[i]))) return hr;// テクスチャーの生成 0180: if( FAILED(hr = pTexture0[i]->GetSurfaceLevel(0,&pTextureSurface0[i]))) return hr; // テクスチャーとサーフェスを関連づける 0181: if( FAILED(hr = lpD3DDev->SetRenderTarget(pTextureSurface0[i], lpZbuffer ))) return hr; // テクスチャー用の描画と深度バッファを関連付ける 0182: 0183: if( FAILED(hr = lpD3DDev->CreateTexture(WIDTH,HEIGHT, 1 ,D3DUSAGE_RENDERTARGET, Desc.Format, D3DPOOL_DEFAULT, &pTexture1[i]))) return hr;// テクスチャーの生成 0184: if( FAILED(hr = pTexture1[i]->GetSurfaceLevel(0,&pTextureSurface1[i]))) return hr; // テクスチャーとサーフェスを関連づける 0185: if( FAILED(hr = lpD3DDev->SetRenderTarget(pTextureSurface1[i], lpZbuffer ))) return hr; // テクスチャー用の描画と深度バッファを関連付ける 0186: } 0187: // 描画を元の画面に戻す 0188: lpD3DDev->SetRenderTarget(pBackbuffer, lpZbuffer ); 0189: 0190: 0191: // 背景部分の初期化 0192: InitBg(lpD3DDev); 0193: 0194: // 不変なレジスタの設定 0195: lpD3DDev->SetRenderState( D3DRS_ZENABLE, TRUE ); 0196: lpD3DDev->SetRenderState( D3DRS_LIGHTING, FALSE ); 0197: lpD3DDev->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE); 0198: lpD3DDev->SetVertexShaderConstant(12, &D3DXVECTOR4(1.0f/1.41421356f, 0.5f, 1.0f, 2.0f), 1); 0199: 0200: 0201: return S_OK; 0202: } 0203: //----------------------------------------------------------------------------- 0204: // Name: Render() 0205: // Desc: Draws the scene 0206: //----------------------------------------------------------------------------- 0207: const float z_min = 0.5f; 0208: const float z_max = 100.0f; 0209: D3DXVECTOR4 lightDir(1.0f, 1.0f, 0.5f, 0.0f); 0210: 0211: VOID DrawModel(LPDIRECT3DDEVICE8 lpD3DDev, unsigned int flag, unsigned int center_flag, int back) 0212: { 0213: D3DXMATRIX mWorld, mView, mProj; 0214: D3DXMATRIX mWorld0; 0215: D3DXMATRIX mWorld1; 0216: D3DXMATRIX m; 0217: D3DXVECTOR4 vl; 0218: DWORD i; 0219: 0220: // ------------------------------------------------------------------------ 0221: // ワールド行列 0222: // ------------------------------------------------------------------------ 0223: 0224: // 外側もでる 0225: int t = timeGetTime()%314159; 0226: D3DXMatrixTranslation(&m, 1.5f*MeshRadius,0,0); 0227: D3DXMatrixRotationY( &mWorld0, t/1000.0f ); 0228: //D3DXMatrixRotationY( &mWorld0, -0.2*PI/2 ); // 撮影角度 0229: mWorld0 = m * mWorld0; 0230: 0231: // 内側もでる 0232: D3DXMatrixRotationY( &mWorld1, -t/3000.0f ); 0233: //D3DXMatrixRotationY( &mWorld1, 1.4f*PI/2 ); // 撮影角度 0234: 0235: // ------------------------------------------------------------------------ 0236: // ビュー行列 0237: // ------------------------------------------------------------------------ 0238: 0239: D3DXVECTOR3 eye(0.0f,1.4f*MeshRadius,2.5f*MeshRadius); 0240: D3DXVECTOR3 lookAt(0.0f, 0.0f, 0.0f); 0241: D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); 0242: 0243: switch(center_flag){ 0244: case RENDER_CAR0: 0245: eye.x = mWorld0._41; 0246: eye.y = mWorld0._42+0.4f*MeshRadius; 0247: eye.z = mWorld0._43; 0248: lookAt.x = eye.x; 0249: lookAt.y = eye.y; 0250: if(back){ 0251: lookAt.z = eye.z-1.0f; 0252: }else{ 0253: lookAt.z = eye.z+1.0f; 0254: } 0255: break; 0256: case RENDER_CAR1: 0257: eye.x = mWorld1._41; 0258: eye.y = mWorld1._42+0.4f*MeshRadius; 0259: eye.z = mWorld1._43; 0260: lookAt.x = eye.x; 0261: lookAt.y = eye.y; 0262: if(back){ 0263: lookAt.z = eye.z-1.0f; 0264: }else{ 0265: lookAt.z = eye.z+1.0f; 0266: } 0267: break; 0268: case RENDER_BG: 0269: default: 0270: break; 0271: } 0272: lpD3DDev->SetVertexShaderConstant(16, &eye, 1); 0273: D3DXMatrixLookAtLH(&mView, &eye, &lookAt, &up); 0274: 0275: D3DXVECTOR3 ne = lookAt-eye; 0276: D3DXVec3Normalize(&ne,&ne); 0277: 0278: // 射影行列(比較用) 0279: D3DXMatrixPerspectiveFovLH(&mProj 0280: , D3DXToRadian(60.0f) // 視野角 0281: , (float)WIDTH/(float)HEIGHT // アスペクト比 0282: , 0.1f, 100.f // 最近接距離,最遠方距離 0283: ); 0284: D3DXMatrixTranspose( &mProj , &mProj); 0285: lpD3DDev->SetVertexShaderConstant(4,&mProj, 4); 0286: 0287: lpD3DDev->SetVertexShaderConstant(15, &D3DXVECTOR4(z_max/(z_max-z_min), -z_max*z_min/(z_max-z_min), 0.0f, 0.0f), 1); 0288: 0289: 0290: // 0291: // 外側もでる描画 0292: // 0293: lpD3DDev->SetStreamSource(0, pMeshVB, sizeof(D3D_CUSTOMVERTEX)); 0294: lpD3DDev->SetIndices(pMeshIndex,0); 0295: 0296: if(flag&RENDER_CAR0){ 0297: D3DXVECTOR3 nw = D3DXVECTOR3(mWorld0._41,mWorld0._42,mWorld0._43)-eye; 0298: D3DXVec3Normalize(&nw,&nw); 0299: if(-0.7f<nw.x*ne.x+nw.y*ne.y+nw.z*ne.z){ 0300: m = mWorld0 * mView; 0301: D3DXMatrixTranspose( &m , &m); 0302: lpD3DDev->SetVertexShaderConstant(0,&m, 4); 0303: D3DXMatrixTranspose( &m , &mWorld0); 0304: lpD3DDev->SetVertexShaderConstant(8,&m, 4); 0305: 0306: D3DXMatrixInverse( &m, NULL, &mWorld0); 0307: D3DXVec4Transform(&vl, &lightDir, &m); 0308: D3DXVec4Normalize(&vl, &vl); 0309: vl[3] = 0.1f;// w成分は環境色の強さ 0310: lpD3DDev->SetVertexShaderConstant(13, &vl, 1); 0311: 0312: for(i=0;i<dwNumMaterials;i++){ 0313: //色をセット 0314: D3DXVECTOR4 vl; 0315: vl.x = pMeshMaterials[i].Diffuse.r; 0316: vl.y = pMeshMaterials[i].Diffuse.g; 0317: vl.z = pMeshMaterials[i].Diffuse.b; 0318: lpD3DDev->SetVertexShaderConstant(14, &vl, 1); 0319: 0320: lpD3DDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0321: pSubsetTable[i].VertexStart, 0322: pSubsetTable[i].VertexCount, 0323: pSubsetTable[i].FaceStart * 3, 0324: pSubsetTable[i].FaceCount); 0325: } 0326: } 0327: } 0328: // 0329: // モデル2 0330: // 0331: if(flag&RENDER_CAR1){ 0332: D3DXVECTOR3 nw = D3DXVECTOR3(mWorld1._41,mWorld1._42,mWorld1._43)-eye; 0333: D3DXVec3Normalize(&nw,&nw); 0334: if(-0.7f<nw.x*ne.x+nw.y*ne.y+nw.z*ne.z){ 0335: m = mWorld1 * mView; 0336: D3DXMatrixTranspose( &m , &m); 0337: lpD3DDev->SetVertexShaderConstant(0,&m, 4); 0338: D3DXMatrixTranspose( &m , &mWorld1); 0339: lpD3DDev->SetVertexShaderConstant(8,&m, 4); 0340: 0341: D3DXMatrixInverse( &m, NULL, &mWorld1); 0342: D3DXVec4Transform(&vl, &lightDir, &m); 0343: D3DXVec4Normalize(&vl, &vl); 0344: vl[3] = 0.1f;// w成分は環境色の強さ 0345: lpD3DDev->SetVertexShaderConstant(13, &vl, 1); 0346: 0347: for(i=0;i<dwNumMaterials;i++){ 0348: //色をセット 0349: D3DXVECTOR4 vl; 0350: vl.x = pMeshMaterials[i].Diffuse.r; 0351: vl.y = pMeshMaterials[i].Diffuse.g; 0352: vl.z = pMeshMaterials[i].Diffuse.b; 0353: lpD3DDev->SetVertexShaderConstant(14, &vl, 1); 0354: 0355: lpD3DDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0356: pSubsetTable[i].VertexStart, 0357: pSubsetTable[i].VertexCount, 0358: pSubsetTable[i].FaceStart * 3, 0359: pSubsetTable[i].FaceCount); 0360: } 0361: } 0362: } 0363: 0364: // 0365: // 背景描画 0366: // 0367: if(flag&RENDER_BG){ 0368: D3DXMatrixScaling(&mWorld, 3.0f, 3.0f, 3.0f); 0369: m = mWorld * mView; 0370: D3DXMatrixTranspose( &m , &m); 0371: lpD3DDev->SetVertexShaderConstant(0,&m, 4); 0372: 0373: lpD3DDev->SetVertexShaderConstant(13, &D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f), 1); 0374: lpD3DDev->SetVertexShaderConstant(14, &D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f), 1); 0375: DrawBg(lpD3DDev); 0376: } 0377: } 0378: //----------------------------------------------------------------------------- 0379: // Name: Render() 0380: // Desc: Draws the scene 0381: //----------------------------------------------------------------------------- 0382: VOID Render(LPDIRECT3DDEVICE8 lpD3DDev) 0383: { 0384: // ------------------------------------------------------------------------ 0385: // 真中の車(CAR0)のテクスチャーの作成 0386: // ------------------------------------------------------------------------ 0387: // step1 環境マップ1 0388: lpD3DDev->SetVertexShader(hVertexShaderFish); 0389: lpD3DDev->SetPixelShader(hPixelShaderFish); 0390: 0391: lpD3DDev->SetRenderTarget(pTextureSurface0[0], lpZbuffer); 0392: lpD3DDev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x004080, 1.0f, 0L); 0393: lpD3DDev->SetTexture( 0, NULL ); 0394: DrawModel(lpD3DDev, RENDER_CAR1|RENDER_BG, RENDER_CAR0, 0); 0395: 0396: // step2 環境マップ2 0397: lpD3DDev->SetRenderTarget(pTextureSurface0[1], lpZbuffer); 0398: lpD3DDev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x004080, 1.0f, 0L); 0399: lpD3DDev->SetTexture( 0, NULL ); 0400: DrawModel(lpD3DDev, RENDER_CAR1|RENDER_BG, RENDER_CAR0, 1); 0401: 0402: // ------------------------------------------------------------------------ 0403: // 外側の車(CAR1)のテクスチャーの作成 0404: // ------------------------------------------------------------------------ 0405: // step1 環境マップ1 0406: lpD3DDev->SetRenderTarget(pTextureSurface1[0], lpZbuffer); 0407: lpD3DDev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x004080, 1.0f, 0L); 0408: lpD3DDev->SetTexture( 0, NULL ); 0409: DrawModel(lpD3DDev, RENDER_CAR0|RENDER_BG, RENDER_CAR1, 0); 0410: // step2 環境マップ2 0411: lpD3DDev->SetRenderTarget(pTextureSurface1[1], lpZbuffer); 0412: lpD3DDev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x004080, 1.0f, 0L); 0413: lpD3DDev->SetTexture( 0, NULL ); 0414: DrawModel(lpD3DDev, RENDER_CAR0|RENDER_BG, RENDER_CAR1, 1); 0415: // ------------------------------------------------------------------------ 0416: // スクリーンに描画 0417: // ------------------------------------------------------------------------ 0418: // 描画を戻す 0419: lpD3DDev->SetRenderTarget(pBackbuffer, lpZbuffer ); 0420: lpD3DDev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000, 1.0f, 0L); 0421: lpD3DDev->SetVertexShader(hVertexShaderDPEM); 0422: lpD3DDev->SetPixelShader(hPixelShaderDPEM); 0423: 0424: // step1 車0描画 0425: lpD3DDev->SetTexture( 0, pTexture0[0] ); 0426: lpD3DDev->SetTexture( 1, pTexture0[1] ); 0427: DrawModel(lpD3DDev, RENDER_CAR0, RENDER_BG, -1); 0428: 0429: // step2 車1描画 0430: lpD3DDev->SetTexture( 0, pTexture1[0] ); 0431: lpD3DDev->SetTexture( 1, pTexture1[1] ); 0432: DrawModel(lpD3DDev, RENDER_CAR1, RENDER_BG, -1); 0433: 0434: // step3 背景描画 0435: lpD3DDev->SetVertexShader(hVertexShader); 0436: lpD3DDev->SetPixelShader(hPixelShader); 0437: lpD3DDev->SetTexture( 0, NULL ); 0438: lpD3DDev->SetTexture( 1, NULL ); 0439: lpD3DDev->SetTexture( 2, NULL ); 0440: DrawModel(lpD3DDev, RENDER_BG, RENDER_BG, -1); 0441: 0442: // ------------------------------------------------------------------------ 0443: // 念のため、他のレンダーでおかしくならないように 0444: // ------------------------------------------------------------------------ 0445: lpD3DDev->SetTexture( 0, NULL ); 0446: lpD3DDev->SetTexture( 1, NULL ); 0447: lpD3DDev->SetPixelShader(0); 0448: 0449: #if 1 0450: // 描画した画面をテクスチャーとして描く 0451: { 0452: struct TLVERTEX 0453: { 0454: float x,y,z,rhw; 0455: float tu,tv; 0456: }; 0457: #define FVF_TLVERTEX (D3DFVF_XYZRHW | D3DFVF_TEX1) 0458: lpD3DDev->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); 0459: lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); 0460: lpD3DDev->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_DISABLE); 0461: float scale = 128.0f; 0462: TLVERTEX Vertex[4] = { 0463: // x y z rhw tu tv 0464: { 0, 0,0, 1, 0, 0,}, 0465: {scale, 0,0, 1, 1, 0,}, 0466: {scale,scale,0, 1, 1, 1,}, 0467: { 0,scale,0, 1, 0, 1,}, 0468: }; 0469: lpD3DDev->SetTexture( 0, pTexture0[0] ); 0470: lpD3DDev->SetVertexShader( FVF_TLVERTEX ); 0471: lpD3DDev->SetPixelShader(0); 0472: lpD3DDev->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, Vertex, sizeof( TLVERTEX ) ); 0473: } 0474: { 0475: struct TLVERTEX 0476: { 0477: float x,y,z,rhw; 0478: float tu,tv; 0479: }; 0480: #define FVF_TLVERTEX (D3DFVF_XYZRHW | D3DFVF_TEX1) 0481: lpD3DDev->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); 0482: lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); 0483: lpD3DDev->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_DISABLE); 0484: float scale = 128.0f; 0485: TLVERTEX Vertex[4] = { 0486: // x y z rhw tu tv 0487: { scale, 0,0, 1, 0, 0,}, 0488: {2*scale, 0,0, 1, 1, 0,}, 0489: {2*scale,scale,0, 1, 1, 1,}, 0490: { scale,scale,0, 1, 0, 1,}, 0491: }; 0492: lpD3DDev->SetTexture( 0, pTexture0[1] ); 0493: lpD3DDev->SetVertexShader( FVF_TLVERTEX ); 0494: lpD3DDev->SetPixelShader(0); 0495: lpD3DDev->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, Vertex, sizeof( TLVERTEX ) ); 0496: } 0497: { 0498: struct TLVERTEX 0499: { 0500: float x,y,z,rhw; 0501: float tu,tv; 0502: }; 0503: #define FVF_TLVERTEX (D3DFVF_XYZRHW | D3DFVF_TEX1) 0504: lpD3DDev->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); 0505: lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); 0506: lpD3DDev->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_DISABLE); 0507: float scale = 128.0f; 0508: TLVERTEX Vertex[4] = { 0509: // x y z rhw tu tv 0510: {2*scale, 0,0, 1, 0, 0,}, 0511: {3*scale, 0,0, 1, 1, 0,}, 0512: {3*scale,scale,0, 1, 1, 1,}, 0513: {2*scale,scale,0, 1, 0, 1,}, 0514: }; 0515: lpD3DDev->SetTexture( 0, pTexture1[0] ); 0516: lpD3DDev->SetVertexShader( FVF_TLVERTEX ); 0517: lpD3DDev->SetPixelShader(0); 0518: lpD3DDev->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, Vertex, sizeof( TLVERTEX ) ); 0519: } 0520: { 0521: struct TLVERTEX 0522: { 0523: float x,y,z,rhw; 0524: float tu,tv; 0525: }; 0526: #define FVF_TLVERTEX (D3DFVF_XYZRHW | D3DFVF_TEX1) 0527: lpD3DDev->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); 0528: lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); 0529: lpD3DDev->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_DISABLE); 0530: float scale = 128.0f; 0531: TLVERTEX Vertex[4] = { 0532: // x y z rhw tu tv 0533: {3*scale, 0,0, 1, 0, 0,}, 0534: {4*scale, 0,0, 1, 1, 0,}, 0535: {4*scale,scale,0, 1, 1, 1,}, 0536: {3*scale,scale,0, 1, 0, 1,}, 0537: }; 0538: lpD3DDev->SetTexture( 0, pTexture1[1] ); 0539: lpD3DDev->SetVertexShader( FVF_TLVERTEX ); 0540: lpD3DDev->SetPixelShader(0); 0541: lpD3DDev->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, Vertex, sizeof( TLVERTEX ) ); 0542: } 0543: #endif 0544: } 0545: //----------------------------------------------------------------------------- 0546: // メッシュオブジェクト削除 0547: //----------------------------------------------------------------------------- 0548: void DeleteMeshObject(void) 0549: { 0550: DWORD i; 0551: 0552: if(pMeshVB == NULL) return; 0553: 0554: for(i=0; i<dwNumMaterials; i++){ 0555: RELEASE(pMeshTextures[i]); 0556: } 0557: delete[] pMeshTextures; 0558: delete[] pMeshMaterials; 0559: delete[] pSubsetTable; 0560: 0561: RELEASE(pMeshVB); 0562: RELEASE(pMeshIndex); 0563: } 0564: //----------------------------------------------------------------------------- 0565: // Name: CleanRender() 0566: // Desc: 後始末 0567: //----------------------------------------------------------------------------- 0568: void CleanRender(LPDIRECT3DDEVICE8 lpD3DDev) 0569: { 0570: CleanBg(lpD3DDev); 0571: 0572: for(int i = 0; i < 2; i++){ 0573: RELEASE(pTexture0[i]); 0574: RELEASE(pTexture1[i]); 0575: RELEASE(pTextureSurface0[i]); 0576: RELEASE(pTextureSurface1[i]); 0577: } 0578: RELEASE(pBackbuffer); 0579: 0580: CPixelShaderMgr::Release(lpD3DDev, &hPixelShaderDPEM); 0581: CVertexShaderMgr::Release(lpD3DDev, &hVertexShaderDPEM); 0582: CPixelShaderMgr::Release(lpD3DDev, &hPixelShaderFish); 0583: CVertexShaderMgr::Release(lpD3DDev, &hVertexShaderFish); 0584: CPixelShaderMgr::Release(lpD3DDev, &hPixelShader); 0585: CVertexShaderMgr::Release(lpD3DDev, &hVertexShader); 0586: 0587: DeleteMeshObject(); 0588: } 0589: