void MirrorDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, 0xffeeeeee, 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(mFX->SetTechnique(mhTech)); HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3))); HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAmbientLight, &mAmbientLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecularLight, &mSpecularLight, sizeof(D3DXCOLOR))); // All objects use the same material. HR(mFX->SetValue(mhAmbientMtrl, &mWhiteMtrl.ambient, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseMtrl, &mWhiteMtrl.diffuse, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecularMtrl, &mWhiteMtrl.spec, sizeof(D3DXCOLOR))); HR(mFX->SetFloat(mhSpecularPower, mWhiteMtrl.specPower)); drawRoom(); drawMirror(); drawTeapot(); drawReflectedTeapot(); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void AmbientDiffuseDemo::drawScene() { HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(mFX->SetTechnique(mhTech)); HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj))); D3DXMATRIX worldInverseTranspose; D3DXMatrixInverse(&worldInverseTranspose, 0, &mWorld); D3DXMatrixTranspose(&worldInverseTranspose, &worldInverseTranspose); HR(mFX->SetMatrix(mhWorldInverseTranspose, &worldInverseTranspose)); HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3))); HR(mFX->SetValue(mhDiffuseMtrl, &mDiffuseMtrl, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAmbientMtrl, &mAmbientMtrl, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAmbientLight, &mAmbientLight, sizeof(D3DXCOLOR))); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); for (UINT i = 0; i < numPasses; ++i) { HR(mFX->BeginPass(i)); HR(mTeapot->DrawSubset(0)); HR(mFX->EndPass()); } HR(mFX->End()); mGfxStats->display(D3DCOLOR_XRGB(0,0,0)); HR(gd3dDevice->EndScene()); HR(gd3dDevice->Present(0, 0, 0, 0)); }
void TriGridDemo::drawScene() { HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(gd3dDevice->SetStreamSource(0, mVB, 0, sizeof(VertexPos))); HR(gd3dDevice->SetIndices(mIB)); HR(gd3dDevice->SetVertexDeclaration(VertexPos::Decl)); HR(mFX->SetTechnique(mhTech)); HR(mFX->SetMatrix(mhWVP, &(mView*mProj))); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); for (UINT i = 0; i < numPasses; ++i) { HR(mFX->BeginPass(i)); HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mNumVertices, 0, mNumTriangles)); HR(mFX->EndPass()); } HR(mFX->End()); mGfxStats->display(D3DCOLOR_XRGB(0,0,0)); HR(gd3dDevice->EndScene()); HR(gd3dDevice->Present(0, 0, 0, 0)); }
void GfxStatsDemo::drawScene() { HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0)); HR(gd3dDevice->BeginScene()); mGfxStats->display(); HR(gd3dDevice->EndScene()); HR(gd3dDevice->Present(0, 0, 0, 0)); }
void MultiTexDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0)); HR(gd3dDevice->BeginScene()); // Setup the rendering FX HR(mFX->SetTechnique(mhTech)); HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj))); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, &mWorld); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans)); HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3))); HR(mFX->SetValue(mhDiffuseMtrl, &mDiffuseMtrl, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAmbientMtrl, &mAmbientMtrl, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAmbientLight, &mAmbientLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecularLight, &mSpecularLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecularMtrl, &mSpecularMtrl, sizeof(D3DXCOLOR))); HR(mFX->SetFloat(mhSpecularPower, mSpecularPower)); HR(mFX->SetMatrix(mhWorld, &mWorld)); HR(mFX->SetTexture(mhTex0, mTex0)); HR(mFX->SetTexture(mhTex1, mTex1)); HR(mFX->SetTexture(mhTex2, mTex2)); HR(mFX->SetTexture(mhBlendMap, mBlendMap)); HR(gd3dDevice->SetVertexDeclaration(VertexPNT::Decl)); HR(gd3dDevice->SetStreamSource(0, mGridVB, 0, sizeof(VertexPNT))); HR(gd3dDevice->SetIndices(mGridIB)); // Begin passes. UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); for(UINT i = 0; i < numPasses; ++i) { HR(mFX->BeginPass(i)); HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mNumGridVertices, 0, mNumGridTriangles)); HR(mFX->EndPass()); } HR(mFX->End()); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void SolarSysDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight))); HR(mFX->SetTechnique(mhTech)); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); // Wrap the texture coordinates that get assigned to TEXCOORD2 in the pixel shader. HR(gd3dDevice->SetRenderState(D3DRS_WRAP2, D3DWRAP_U)); // Build the world transforms for each frame, then render them. buildObjectWorldTransforms(); D3DXMATRIX S; for(int i = 0; i < NUM_OBJECTS; ++i) { float s = mObject[i].size; D3DXMatrixScaling(&S, s, s, s); // Prefix the frame matrix with a scaling transformation to // size it relative to the world. mWorld = S * mObject[i].toWorldXForm; HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj))); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, &mWorld); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans)); HR(mFX->SetMatrix(mhWorld, &mWorld)); HR(mFX->SetValue(mhMtrl, &mWhiteMtrl, sizeof(Mtrl))); HR(mFX->SetTexture(mhTex, mObject[i].tex)); HR(mFX->CommitChanges()); mSphere->DrawSubset(0); } HR(gd3dDevice->SetRenderState(D3DRS_WRAP2, 0)); HR(mFX->EndPass()); HR(mFX->End()); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void WaterDemo::drawScene() { HR(gd3dDevice->BeginScene()); mSky->draw(); HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight))); HR(mFX->SetMatrix(mhWVP, &(mSceneWorld*gCamera->viewProj()))); HR(mFX->SetValue(mhEyePosW, &gCamera->pos(), sizeof(D3DXVECTOR3))); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); for(UINT j = 0; j < mSceneMtrls.size(); ++j) { HR(mFX->SetValue(mhMtrl, &mSceneMtrls[j], sizeof(Mtrl))); // If there is a texture, then use. if(mSceneTextures[j] != 0) { HR(mFX->SetTexture(mhTex, mSceneTextures[j])); } // But if not, then set a pure white texture. When the texture color // is multiplied by the color from lighting, it is like multiplying by // 1 and won't change the color from lighting. else { HR(mFX->SetTexture(mhTex, mWhiteTex)); } HR(mFX->SetTexture(mhNormalMap, mSceneNormalMaps[j])); HR(mFX->CommitChanges()); HR(mSceneMesh->DrawSubset(j)); } HR(mFX->EndPass()); HR(mFX->End()); // Draw alpha blended object last. mWater->draw(); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void DiffusePyramidDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0)); HR(gd3dDevice->BeginScene()); // Let Direct3D know the vertex buffer, index buffer and vertex // declaration we are using. HR(gd3dDevice->SetStreamSource(0, mVB, 0, sizeof(VertexPN))); HR(gd3dDevice->SetVertexDeclaration(VertexPN::Decl)); // Setup the rendering FX HR(mFX->SetTechnique(mhTech)); HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj))); D3DXMATRIX worldInverseTranspose , tmp1; D3DXMatrixInverse(&worldInverseTranspose, 0, &mWorld); D3DXMatrixTranspose(&tmp1, &worldInverseTranspose); ////! debug //if (worldInverseTranspose!=tmp1) //{ // DebugBreak(); //} HR(mFX->SetMatrix(mhWorldInverseTranspose, &worldInverseTranspose)); HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3))); HR(mFX->SetValue(mhDiffuseMtrl, &mDiffuseMtrl, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR))); // Begin passes. UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); for(UINT i = 0; i < numPasses; ++i) { HR(mFX->BeginPass(i)); HR(gd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 4)); HR(mFX->EndPass()); } HR(mFX->End()); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void TerrainDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0)); HR(gd3dDevice->BeginScene()); mTerrain->draw(mView, mProj); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void XFileDemo::drawScene() { HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight))); HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj))); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, &mWorld); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans)); HR(mFX->SetMatrix(mhWorld, &mWorld)); HR(mFX->SetTechnique(mhTech)); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); for (int j = 0; j < mMtrl.size(); ++j) { HR(mFX->SetValue(mhMtrl, &mMtrl[j], sizeof(Material))); if (mTex[j] != 0) { HR(mFX->SetTexture(mhTex, mTex[j])); } else { HR(mFX->SetTexture(mhTex, mWhiteTex)); } HR(mFX->CommitChanges()); HR(mMesh->DrawSubset(j)); } HR(mFX->EndPass()); HR(mFX->End()); mGfxStats->display(D3DCOLOR_XRGB(0,0,0)); HR(gd3dDevice->EndScene()); HR(gd3dDevice->Present(0, 0, 0, 0)); }
void CubeDemo::drawScene() { HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(gd3dDevice->SetStreamSource(0, mVB, 0, sizeof(VertexPos))); HR(gd3dDevice->SetIndices(mIB)); HR(gd3dDevice->SetVertexDeclaration(VertexPos::Decl)); D3DXMATRIX W; D3DXMatrixIdentity(&W); HR(gd3dDevice->SetTransform(D3DTS_WORLD, &W)); HR(gd3dDevice->SetTransform(D3DTS_VIEW, &mView)); HR(gd3dDevice->SetTransform(D3DTS_PROJECTION, &mProj)); HR(gd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME)); HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12)); mGfxStats->display(D3DCOLOR_XRGB(0,0,0)); HR(gd3dDevice->EndScene()); HR(gd3dDevice->Present(0, 0, 0, 0)); }
void ProjTexDemo::drawScene() { HR(gd3dDevice->BeginScene()); // Draw sky first--this also replaces our gd3dDevice->Clear call. //mSky->draw(); HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0)); // Draw the scene mesh. HR(mFX->SetTechnique(mhTech)); HR(mFX->SetMatrix(mhWorldInvTrans, &mSceneWorld)); HR(mFX->SetMatrix(mhWorld, &mSceneWorld)); HR(mFX->SetValue(mhLight, &mLight, sizeof(SpotLight))); HR(mFX->SetMatrix(mhWVP, &(mSceneWorld*gCamera->viewProj()))); HR(mFX->SetValue(mhEyePosW, &gCamera->pos(), sizeof(D3DXVECTOR3))); HR(mFX->SetTexture(mhTex, mSkullTex)); HR(mFX->SetMatrix(mhLightWVP, &mLightWVP)); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); for(UINT j = 0; j < mSceneMtrls.size(); ++j) { HR(mFX->SetValue(mhMtrl, &mSceneMtrls[j], sizeof(Mtrl))); HR(mFX->CommitChanges()); HR(mSceneMesh->DrawSubset(j)); } HR(mFX->EndPass()); HR(mFX->End()); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void SpotlightDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0)); HR(gd3dDevice->BeginScene()); // Setup the rendering FX HR(mFX->SetValue(mhAmbientLight, &mAmbientLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecLight, &mSpecLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAttenuation012, &mAttenuation012, sizeof(D3DXVECTOR3))); HR(mFX->SetFloat(mhSpotPower, mSpotPower)); // Begin passes. UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); for(UINT i = 0; i < numPasses; ++i) { HR(mFX->BeginPass(i)); drawGrid(); drawCylinders(); drawSpheres(); HR(mFX->EndPass()); } HR(mFX->End()); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void GateDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0)); HR(gd3dDevice->BeginScene()); // Setup the rendering FX HR(mFX->SetTechnique(mhTech)); HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3))); HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAmbientLight, &mAmbientLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecularLight, &mSpecularLight, sizeof(D3DXCOLOR))); drawGround(); drawGate(); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void Evolution::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0)); HR(gd3dDevice->BeginScene()); static char buffer[255]; static RECT clientRect = {0, 0, 0, 0}; GetClientRect(mhMainWnd, &clientRect); HR(gd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHAREF, 25)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER)); if (foodList.size() != 0 || eggList.size() != 0) drawEggsFood(); if (lifeformList.size() != 0) drawLifeforms(); if (mbDrawInfo) { sprintf(buffer, "Carnivore: %d\n" "Carnivore Parts: %d\n" "Egg Cycle Length: %f\n" "Egg Time Length: %f\n" "Food Cycle Length: %f\n" "Lifetime Length: %f\n" "Sight Distance: %f\n" "Fear Distance: %f\n" "Pursuit Length: %f\n" "Speed: %f", mDrawInfo.carnivore, mDrawInfo.carnivoreParts, mDrawInfo.eggCycleLength, mDrawInfo.eggTimeLength, mDrawInfo.foodCycleLength, mDrawInfo.lifeTimeLength, mDrawInfo.sightDistance, mDrawInfo.fearDistance, mDrawInfo.pursuitLength, mDrawInfo.speed); RECT N = {clientRect.left, clientRect.top+(4*18), clientRect.left+300, clientRect.top+(14*18)}; HR(mFont->DrawText(0, buffer, -1, &N, DT_LEFT | DT_NOCLIP, D3DCOLOR_XRGB(0, 0, 0))); } /*if (foodList.size() + BellyFoods + eggList.size() != mMaxBio || BellyFoods < 0) { sprintf(buffer, "BIOMASS LOST/GAINED"); RECT N = {clientRect.left, clientRect.top+(4*18), clientRect.left+300, clientRect.top+(13*18)}; HR(mFont->DrawText(0, buffer, -1, &N, DT_LEFT | DT_NOCLIP, D3DCOLOR_XRGB(255, 0, 0))); }*/ mGfxStats->display(); HR(gd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false)); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void RobotArmDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight))); HR(mFX->SetTechnique(mhTech)); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); // Build the world transforms for each bone, then render them. buildBoneWorldTransforms(); D3DXMATRIX T; D3DXMatrixTranslation(&T, -NUM_BONES, 0.0f, 0.0f); for(int i = 0; i < NUM_BONES; ++i) { // Append the transformation with a slight translation to better // center the skeleton at the center of the scene. mWorld = mBones[i].toWorldXForm * T; HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj))); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, &mWorld); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans)); HR(mFX->SetMatrix(mhWorld, &mWorld)); for(int j = 0; j < mMtrl.size(); ++j) { HR(mFX->SetValue(mhMtrl, &mMtrl[j], sizeof(Mtrl))); // If there is a texture, then use. if(mTex[j] != 0) { HR(mFX->SetTexture(mhTex, mTex[j])); } // But if not, then set a pure white texture. When the texture color // is multiplied by the color from lighting, it is like multiplying by // 1 and won't change the color from lighting. else { HR(mFX->SetTexture(mhTex, mWhiteTex)); } HR(mFX->CommitChanges()); HR(mBoneMesh->DrawSubset(j)); } } HR(mFX->EndPass()); HR(mFX->End()); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void PropsDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff888888, 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(mFX->SetValue(mhEyePosW, &gCamera->pos(), sizeof(D3DXVECTOR3))); HR(mFX->SetTechnique(mhTech)); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); drawObject(mCastle, mCastleWorld); // Use alpha test to block non leaf pixels from being rendered in the // trees (i.e., use alpha mask). HR(gd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHAREF, 200)); // Draw the trees: NUM_TREES/4 of each of the four types. for(int i = 0; i < NUM_TREES; ++i) { if( i < NUM_TREES/4 ) drawObject(mTrees[0], mTreeWorlds[i]); else if( i < 2*NUM_TREES/4 ) drawObject(mTrees[1], mTreeWorlds[i]); else if( i < 3*NUM_TREES/4 ) drawObject(mTrees[2], mTreeWorlds[i]); else drawObject(mTrees[3], mTreeWorlds[i]); } HR(gd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false)); HR(mFX->EndPass()); HR(mFX->End()); HR(mGrassFX->SetValue(mhGrassEyePosW, &gCamera->pos(), sizeof(D3DXVECTOR3))); HR(mGrassFX->SetMatrix(mhGrassViewProj, &(gCamera->viewProj()))); HR(mGrassFX->SetFloat(mhGrassTime, mTime)); HR(mGrassFX->Begin(&numPasses, 0)); HR(mGrassFX->BeginPass(0)); // Draw to depth buffer only. HR(mGrassMesh->DrawSubset(0)); HR(mGrassFX->EndPass()); HR(mGrassFX->End()); mTerrain->draw(); mWater->draw(); // draw alpha blended objects last. mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }