//----------------------------------------------------------------------------- // Name: Render() // Desc: Draws the scene //----------------------------------------------------------------------------- VOID Render() { // Clear the backbuffer and the zbuffer g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 ); // Begin the scene if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { SetupCameraMatrices(); SetupLights((timeGetTime() / 1000) % 2); SetupCylinderMatrices(); int TextureIndex = (timeGetTime() / 1000) % 2; g_pd3dDevice->SetTexture(0, g_pTexture[TextureIndex]); g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); #ifdef SHOW_HOW_TO_USE_TCI D3DXMATRIXA16 mTextureTransform; D3DXMATRIXA16 mProj; D3DXMATRIXA16 mTrans; D3DXMATRIXA16 mScale; g_pd3dDevice->GetTransform(D3DTS_PROJECTION, &mProj); D3DXMatrixTranslation(&mTrans, 0.5f, 0.5f, 0.0f); D3DXMatrixScaling(&mScale, 0.5f, -0.5f, 1.0f); mTextureTransform = mProj * mScale * mTrans; g_pd3dDevice->SetTransform(D3DTS_TEXTURE0, &mTextureTransform); g_pd3dDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT4 | D3DTTFF_PROJECTED); g_pd3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION); #endif g_pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX)); g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX); g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2 * 50 - 2); // Meshes are divided into subsets, one for each material. Render them in // a loop for (int loop = 0; loop < MESH_COUNT; ++loop) { // Setup the world, view, and projection matrices SetupMeshesMatrices(loop); for (DWORD i = 0; i < g_dwNumMaterials[loop]; i++) { // Set the material and texture for this subset g_pd3dDevice->SetMaterial(&g_pMeshMaterials[loop][i]); g_pd3dDevice->SetTexture(0, g_pMeshTextures[loop][i]); // Draw the mesh subset g_pMesh[loop]->DrawSubset(0); } } // End the scene g_pd3dDevice->EndScene(); } // Present the backbuffer contents to the display g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); }
VOID Render() { g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 ); // Begin the scene if ( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { // Setup the world, view, and projection matrices SetupCylinderMatrices(); // Setup the Lights and materials SetupLightEnvironment(); // swtich Light every one second if ( HeartBeatOneSecond() ) { SetupLights1(); LoadBananaTexture(); } else { SetUpLights2(); LoadStoneTexture(); } g_pd3dDevice->SetTexture( 0, g_pTexture ); g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); // Render the vertex buffer contents g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) ); g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 * 50 - 2 ); // setup Tiger matrix SetupTigerMatrices(); // draw Tiger if ( SUCCEEDED( LoadMesh() ) ) { for ( DWORD i = 0; i < g_dwNumMaterials; ++i ) { g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] ); g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] ); g_pMesh->DrawSubset( i ); } } // setup Tiger 2 matrix SetupTigerSecondMatrices(); if ( SUCCEEDED( LoadSecondMesh() ) ) { for ( DWORD i = 0; i < g_dwNumMaterialsSecond; ++i ) { g_pd3dDevice->SetMaterial( &g_pMeshMaterialsSecond[i] ); g_pd3dDevice->SetTexture( 0, g_pMeshTexturesSecond[i] ); g_pMeshSecond->DrawSubset( i ); } } // End the scene g_pd3dDevice->EndScene(); } // Present the backbuffer contents to the display g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); }