Example #1
0
//-----------------------------------------------------------------------------
// Name: RestoreDeviceObjects()
// Desc: Restore device-memory objects and state after a device is created or
//       resized.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::RestoreDeviceObjects()
{
    // InitDeviceObjects for file objects (build textures and vertex buffers)
    m_pShinyTeapot->RestoreDeviceObjects( m_pd3dDevice );
    m_pSkyBox->RestoreDeviceObjects( m_pd3dDevice );
    m_pFont->RestoreDeviceObjects();
    m_pEffect->OnResetDevice();
    m_pEffect->SetTexture( "texSphereMap", m_pSphereMap );

    // Set the transform matrices
    FLOAT fAspect = (FLOAT) m_d3dsdBackBuffer.Width / (FLOAT) m_d3dsdBackBuffer.Height;
    D3DXMatrixPerspectiveFovLH( &m_matProject, D3DX_PI * 0.4f, fAspect, 0.5f, 100.0f );
    return S_OK;
}
Example #2
0
void Evolution::buildFX()
{
    ID3DXBuffer* errors = 0;
    if ( D3DXCreateEffectFromFile(gd3dDevice, "EvolutionShader.fx", 0, 0, D3DXSHADER_DEBUG, 0, &mFX, &errors) )
        if ( !errors )
        {
            MessageBox(0, "EvolutionShader.fx not found! D:", 0, 0);
            PostQuitMessage(0);
        }

    if( errors )
        MessageBox(0, (char*)errors->GetBufferPointer(), 0, 0);

    mhEFTech = mFX->GetTechniqueByName("EFEvolutionShader");
    mhLTech = mFX->GetTechniqueByName("LEvolutionShader");


    mhWVP			 = mFX->GetParameterByName(0, "gWVP");
    mhTex            = mFX->GetParameterByName(0, "gTex");
    mhTex2           = mFX->GetParameterByName(0, "gTex2");
    mhTex3           = mFX->GetParameterByName(0, "gTex3");

    HR(mFX->SetTexture(mhTex,  mFoodTex));
    HR(mFX->SetTexture(mhTex2, mEggTex));
    HR(mFX->SetTexture(mhTex3, mLifeformTex));
}
Example #3
0
void PropsDemo::onResetDevice()
{
	mGfxStats->onResetDevice();
	mTerrain->onResetDevice();
	mWater->onResetDevice();
	HR(mFX->OnResetDevice());
	HR(mGrassFX->OnResetDevice());

	// The aspect ratio depends on the backbuffer dimensions, which can 
	// possibly change after a reset.  So rebuild the projection matrix.
	float w = (float)md3dPP.BackBufferWidth;
	float h = (float)md3dPP.BackBufferHeight;
	gCamera->setLens(D3DX_PI * 0.25f, w/h, 1.0f, 1000.0f);
}
Example #4
0
void MirrorDemo::drawTeapot()
{
	// Cylindrically interpolate texture coordinates.
	HR(gd3dDevice->SetRenderState(D3DRS_WRAP0, D3DWRAPCOORD_0));

	HR(mFX->SetMatrix(mhWVP, &(mTeapotWorld*mView*mProj)));
	D3DXMATRIX worldInvTrans;
	D3DXMatrixInverse(&worldInvTrans, 0, &mTeapotWorld);
	D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans);
	HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans));
	HR(mFX->SetMatrix(mhWorld, &mTeapotWorld));
	HR(mFX->SetTexture(mhTex, mTeapotTex));

	// Begin passes.
	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());

	// Disable wrap.
	HR(gd3dDevice->SetRenderState(D3DRS_WRAP0, 0));
}
Example #5
0
void MirrorDemo::drawMirror()
{
	HR(mFX->SetMatrix(mhWVP, &(mRoomWorld*mView*mProj)));
	D3DXMATRIX worldInvTrans;
	D3DXMatrixInverse(&worldInvTrans, 0, &mRoomWorld);
	D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans);
	HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans));
	HR(mFX->SetMatrix(mhWorld, &mRoomWorld));
	HR(mFX->SetTexture(mhTex, mMirrorTex));

	HR(gd3dDevice->SetVertexDeclaration(VertexPNT::Decl));
	HR(gd3dDevice->SetStreamSource(0, mRoomVB, 0, sizeof(VertexPNT)));

	// Begin passes.
	UINT numPasses = 0;
	HR(mFX->Begin(&numPasses, 0));
	for(UINT i = 0; i < numPasses; ++i)
	{
		HR(mFX->BeginPass(i));

		// draw the mirror
		HR(gd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 18, 2));

		HR(mFX->EndPass());
	}
	HR(mFX->End());
}
Example #6
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));
}
Example #7
0
void StencilMirrorDemo::onResetDevice()
{
	mGfxStats->onResetDevice();
	HR(mFX->OnResetDevice());

	buildProjMtx();
}
Example #8
0
void XFileDemo::onResetDevice()
{
	mGfxStats->onResetDevice();
	HR(mFX->OnResetDevice());

	buildProjMtx();
}
Example #9
0
void AmbientDiffuseDemo::onResetDevice()
{
    mGfxStats->onResetDevice();
    HR(mFX->OnResetDevice());

    buildProjMtx();
}
Example #10
0
void WaterDemo::onLostDevice()
{
    mGfxStats->onLostDevice();
    mSky->onLostDevice();
    mWater->onLostDevice();
    HR(mFX->OnLostDevice());
}
Example #11
0
void Game::drawScene()
{

	// Clear the backbuffer and depth buffer.
	HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, gMyGameWorld->Background(), 1.0f, 0));

	HR(gd3dDevice->BeginScene());

	// Setup the rendering FX
	HR(mFX->SetTechnique(mhTech));
	
	//gMyGameWorld->Render(mFX, mhWVP, mView, mProj);
	gMyGameWorld->Render(mFX, mhWVP, DXCI->getView(), mProj);

	displayGfxStats();

	//sprite
	mSprite->Begin(D3DXSPRITE_ALPHABLEND);

	mSprite->Flush();
	mSprite->End();

	HR(gd3dDevice->EndScene());

	// Present the backbuffer.
	HR(gd3dDevice->Present(0, 0, 0, 0));


}
Example #12
0
void MirrorDemo::drawReflectedTeapot()
{
	HR(gd3dDevice->SetRenderState(D3DRS_STENCILENABLE,    true));
	HR(gd3dDevice->SetRenderState(D3DRS_STENCILFUNC,      D3DCMP_ALWAYS));
	HR(gd3dDevice->SetRenderState(D3DRS_STENCILREF,       0x1));
	HR(gd3dDevice->SetRenderState(D3DRS_STENCILMASK,      0xffffffff));
	HR(gd3dDevice->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff));
	HR(gd3dDevice->SetRenderState(D3DRS_STENCILZFAIL,     D3DSTENCILOP_KEEP));
	HR(gd3dDevice->SetRenderState(D3DRS_STENCILFAIL,      D3DSTENCILOP_KEEP));
	HR(gd3dDevice->SetRenderState(D3DRS_STENCILPASS,      D3DSTENCILOP_REPLACE));

	// Disable writes to the depth and back buffers
	HR(gd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, false));
	HR(gd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true));
	HR(gd3dDevice->SetRenderState(D3DRS_SRCBLEND,  D3DBLEND_ZERO));
	HR(gd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE));

	// Draw mirror to stencil only.
	drawMirror();

	// Re-enable depth writes
	HR(gd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, true ));

	// Only draw reflected teapot to the pixels where the mirror
	// was drawn to.
	HR(gd3dDevice->SetRenderState(D3DRS_STENCILFUNC,  D3DCMP_EQUAL));
	HR(gd3dDevice->SetRenderState(D3DRS_STENCILPASS,  D3DSTENCILOP_KEEP));

	// Build Reflection transformation.
	D3DXMATRIX R;
	D3DXPLANE plane(0.0f, 0.0f, 1.0f, 0.0f); // xy plane
	D3DXMatrixReflect(&R, &plane);

	// Save the original teapot world matrix.
	D3DXMATRIX oldTeapotWorld = mTeapotWorld;

	// Add reflection transform.
	mTeapotWorld = mTeapotWorld * R;

	// Reflect light vector also.
	D3DXVECTOR3 oldLightVecW = mLightVecW;
	D3DXVec3TransformNormal(&mLightVecW, &mLightVecW, &R);
	HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3)));

	// Disable depth buffer and render the reflected teapot.
	HR(gd3dDevice->SetRenderState(D3DRS_ZENABLE, false));
	HR(gd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false));

	// Finally, draw the reflected teapot
	HR(gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW));
	drawTeapot();
	mTeapotWorld = oldTeapotWorld;
	mLightVecW   = oldLightVecW;

	// Restore render states.
	HR(gd3dDevice->SetRenderState(D3DRS_ZENABLE, true));
	HR(gd3dDevice->SetRenderState( D3DRS_STENCILENABLE, false));
	HR(gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW));
}
Example #13
0
void Game::onLostDevice()
{
	HR(mFX->OnLostDevice());
	HR(mFont->OnLostDevice());

	gMyGameWorld->OnLostDevice();
	mSprite->OnLostDevice();
}
Example #14
0
//-------------------------------------------------------------------------------
int CMaterialManager::SetupMaterial (
    AssetHelper::MeshHelper* pcMesh,
    const aiMatrix4x4& pcProj,
    const aiMatrix4x4& aiMe,
    const aiMatrix4x4& pcCam,
    const aiVector3D& vPos)
{
    ai_assert(NULL != pcMesh);
    if (!pcMesh->piEffect)return 0;

    ID3DXEffect* piEnd = pcMesh->piEffect;

    piEnd->SetMatrix("WorldViewProjection",
        (const D3DXMATRIX*)&pcProj);

    piEnd->SetMatrix("World",(const D3DXMATRIX*)&aiMe);
    piEnd->SetMatrix("WorldInverseTranspose",
        (const D3DXMATRIX*)&pcCam);

    D3DXVECTOR4 apcVec[5];
    memset(apcVec,0,sizeof(apcVec));
    apcVec[0].x = g_avLightDirs[0].x;
    apcVec[0].y = g_avLightDirs[0].y;
    apcVec[0].z = g_avLightDirs[0].z;
    apcVec[0].w = 0.0f;
    apcVec[1].x = g_avLightDirs[0].x * -1.0f;
    apcVec[1].y = g_avLightDirs[0].y * -1.0f;
    apcVec[1].z = g_avLightDirs[0].z * -1.0f;
    apcVec[1].w = 0.0f;
    D3DXVec4Normalize(&apcVec[0],&apcVec[0]);
    D3DXVec4Normalize(&apcVec[1],&apcVec[1]);
    piEnd->SetVectorArray("afLightDir",apcVec,5);

    apcVec[0].x = ((g_avLightColors[0] >> 16)   & 0xFF) / 255.0f;
    apcVec[0].y = ((g_avLightColors[0] >> 8)    & 0xFF) / 255.0f;
    apcVec[0].z = ((g_avLightColors[0])         & 0xFF) / 255.0f;
    apcVec[0].w = 1.0f;

    if( g_sOptions.b3Lights)
    {
        apcVec[1].x = ((g_avLightColors[1] >> 16) & 0xFF) / 255.0f;
        apcVec[1].y = ((g_avLightColors[1] >> 8) & 0xFF) / 255.0f;
        apcVec[1].z = ((g_avLightColors[1]) & 0xFF) / 255.0f;
        apcVec[1].w = 0.0f;
    } else
Example #15
0
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));
}
Example #16
0
void RCBindEffect::execute( Renderer& renderer )
{
   DX9Renderer& dxRenderer = static_cast< DX9Renderer& >( renderer );

   ID3DXEffect* dxEffect = dxRenderer.getEffect( m_shader );
   if ( !dxEffect )
   {
      return;
   }

   // set the shader parameters
   dxEffect->SetTechnique( m_techniqueName.c_str() );
   setParams( renderer, dxEffect );

   // begin the rendering process
   unsigned int passesCount;
   dxEffect->Begin( &passesCount, 0 );
}
Example #17
0
void SolarSysDemo::onResetDevice()
{
	mGfxStats->onResetDevice();
	HR(mFX->OnResetDevice());

	// The aspect ratio depends on the backbuffer dimensions, which can 
	// possibly change after a reset.  So rebuild the projection matrix.
	buildProjMtx();
}
Example #18
0
void Evolution::onResetDevice()
{
    mGfxStats->onResetDevice();
    HR(mFont->OnResetDevice());

    HR(mFX->OnResetDevice());

    buildProjMtx();
}
Example #19
0
void SpotlightDemo::buildViewMtx()
{
	float x = mCameraRadius * cosf(mCameraRotationY);
	float z = mCameraRadius * sinf(mCameraRotationY);
	D3DXVECTOR3 pos(x, mCameraHeight, z);
	D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
	D3DXMatrixLookAtLH(&mView, &pos, &target, &up);

	HR(mFX->SetValue(mhEyePos, &pos, sizeof(D3DXVECTOR3)));

	// Spotlight position is the same as the camera position.
	HR(mFX->SetValue(mhLightPosW, &pos, sizeof(D3DXVECTOR3)));

	// Spotlight direction is the same as the camera forward direction.
	D3DXVECTOR3 lightDir = target - pos;
	D3DXVec3Normalize(&lightDir, &lightDir);
	HR(mFX->SetValue(mhLightDirW, &lightDir, sizeof(D3DXVECTOR3)));
}
////////////////////////////////////////////////////////////////
//
// CEffectTemplateImpl::CloneD3DEffect
//
// Clone the d3d effect
//
////////////////////////////////////////////////////////////////
ID3DXEffect* CEffectTemplateImpl::CloneD3DEffect ( SString& strOutStatus, bool& bOutUsesVertexShader, bool& bOutUsesDepthBuffer )
{
    // Clone D3DXEffect
    ID3DXEffect* pNewD3DEffect = NULL;
    LPDIRECT3DDEVICE9 pDevice = NULL;
    m_pD3DEffect->GetDevice ( &pDevice );
    m_pD3DEffect->CloneEffect ( pDevice, &pNewD3DEffect );

    if ( !pNewD3DEffect )
        return NULL;

    // Set the same technique
    {
        D3DXHANDLE hTechnique = m_pD3DEffect->GetCurrentTechnique ();
        D3DXTECHNIQUE_DESC TechniqueDesc;
        m_pD3DEffect->GetTechniqueDesc( hTechnique, &TechniqueDesc );
        pNewD3DEffect->SetTechnique ( pNewD3DEffect->GetTechniqueByName ( TechniqueDesc.Name ) );

        // Output technique name
        strOutStatus = TechniqueDesc.Name;
    }

    // Check if any technique uses a vertex shader
    bOutUsesVertexShader = false;
    D3DXEFFECT_DESC EffectDesc;
    m_pD3DEffect->GetDesc ( &EffectDesc );
    for ( uint i = 0 ; i < EffectDesc.Techniques ; i++ )
    {
        D3DXHANDLE hTechnique = m_pD3DEffect->GetTechnique ( i );
        D3DXTECHNIQUE_DESC TechniqueDesc;
        m_pD3DEffect->GetTechniqueDesc( hTechnique, &TechniqueDesc );
        for ( uint i = 0 ; i < TechniqueDesc.Passes ; i++ )
        {
            D3DXPASS_DESC PassDesc;
            m_pD3DEffect->GetPassDesc ( m_pD3DEffect->GetPass ( hTechnique, i ), &PassDesc );
            if ( PassDesc.pVertexShaderFunction )
                bOutUsesVertexShader = true;
        }
    }

    bOutUsesDepthBuffer = m_bUsesDepthBuffer;

    // Add to list of clones
    assert ( !MapContains ( m_CloneList, pNewD3DEffect ) );
    MapInsert ( m_CloneList, pNewD3DEffect );
    return pNewD3DEffect;
}
Example #21
0
//-----------------------------------------------------------------------------
// Name: InvalidateDeviceObjects()
// Desc: Called when the device-dependent objects are about to be lost.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::InvalidateDeviceObjects()
{
    m_pShinyTeapot->InvalidateDeviceObjects();
    m_pSkyBox->InvalidateDeviceObjects();
    m_pFont->InvalidateDeviceObjects();

    if(m_pEffect)
        m_pEffect->OnLostDevice();

    return S_OK;
}
Example #22
0
void MultiTexDemo::buildViewMtx()
{
	float x = mCameraRadius * cosf(mCameraRotationY);
	float z = mCameraRadius * sinf(mCameraRotationY);
	D3DXVECTOR3 pos(x, mCameraHeight, z);
	D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
	D3DXMatrixLookAtLH(&mView, &pos, &target, &up);

	HR(mFX->SetValue(mhEyePos, &pos, sizeof(D3DXVECTOR3)));
}
Example #23
0
void Game::onResetDevice()
{
	HR(mFX->OnResetDevice());
	HR(mFont->OnResetDevice());

	gMyGameWorld->OnResetDevice();
	mSprite->OnResetDevice();

	// The aspect ratio depends on the backbuffer dimensions, which can 
	// possibly change after a reset.  So rebuild the projection matrix.
	buildProjMtx();
}
Example #24
0
void TriPickDemo::onResetDevice()
{
	HR(m_FX->OnResetDevice());
	HR(m_pCharacter->GetEffect()->OnResetDevice());
	//Aspect ratio rely on the size of back buffer 
	//Back buffer will change when user change window size, so we need to reset project matrix.
	float w = (float)md3dPP.BackBufferWidth;
	float h = (float)md3dPP.BackBufferHeight;

	g_Camera->setLens(D3DX_PI * 0.25f, w / h, 0.1f, 1000.0f);

}
Example #25
0
	void Close()
	{
		if(effect)
			effect->Release();
		effect=null;
		if(ps)
			ps->Release();
		ps=null;
		if(vb)
			vb->Release();
		vb=null;
	}
Example #26
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 CExplodingBullet::Render()
{
	if(GetType() == SMASHBULLET)
		return;
	CAssetManager* pAM = CAssetManager::GetInstance();
	D3DXMATRIX ViewProj = CGameplayState::GetInstance()->GetCamera()->GetViewProjMatrix();
	CRenderer* pRenderer = CRenderer::GetInstance();
	IDirect3DDevice9* pD3D = pRenderer->GetDirect3DDevice();

	pD3D->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
	pD3D->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	pD3D->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

	pD3D->SetVertexDeclaration(pAM->GetVertexDeclaration(BASEOBJECTDECL));
	ID3DXEffect* pShader = pAM->GetShader(EFFECT_OBJ_SPHERE);
	unsigned passes(0);
	pShader->Begin(&passes,0);
	for(unsigned i(0);i < passes; i++)
	{
		pShader->BeginPass(i);

		pShader->SetTexture("gDiffuseTexture", pAM->GetTexture(EFFECT_OBJ_SPHERE));
		pShader->SetMatrix("gViewProjection", &(ViewProj));
		D3DXMATRIX scaleMat, worldMat;
		float scale = GetRadius();
		D3DXMatrixScaling(&scaleMat, scale, scale, scale);
		pShader->SetMatrix("gWorld",&(scaleMat*GetMatrix()));
		pShader->SetFloatArray("gColor", GetColor(), 4);
		pShader->CommitChanges();

		pD3D->SetVertexDeclaration(pAM->GetVertexDeclaration(BASEOBJECTDECL));
		pD3D->SetStreamSource(0, pAM->GetVertBuffer(EFFECT_OBJ_SPHERE), 0, sizeof(tVertex));
		pD3D->SetIndices(pAM->GetIndexBuffer(EFFECT_OBJ_SPHERE));
		pD3D->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, pAM->GetNumVerts(EFFECT_OBJ_SPHERE), 0, pAM->GetNumTriangles(EFFECT_OBJ_SPHERE));

		pShader->EndPass();
	}
	pShader->End();
	pD3D->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
}
Example #28
0
void ProjTexDemo::buildFX()
{
	// Create the FX from a .fx file.
	ID3DXBuffer* errors = 0;
	HR(D3DXCreateEffectFromFile(gd3dDevice, "ProjTex.fx", 
		0, 0, D3DXSHADER_DEBUG|D3DXSHADER_SKIPOPTIMIZATION, 0, &mFX, &errors));
	if( errors )
		MessageBox(0, (char*)errors->GetBufferPointer(), 0, 0);

	// Obtain handles.
	mhTech            = mFX->GetTechniqueByName("ProjTexTech");
	mhWVP             = mFX->GetParameterByName(0, "gWVP");
	mhLightWVP        = mFX->GetParameterByName(0, "gLightWVP");
	mhWorldInvTrans   = mFX->GetParameterByName(0, "gWorldInvTrans");
	mhMtrl            = mFX->GetParameterByName(0, "gMtrl");
	mhLight           = mFX->GetParameterByName(0, "gLight");
	mhEyePosW         = mFX->GetParameterByName(0, "gEyePosW");
	mhWorld           = mFX->GetParameterByName(0, "gWorld");
	mhTex             = mFX->GetParameterByName(0, "gTex");
}
Example #29
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));
}
Example #30
0
void XFileDemo::buildFX()
{
	ID3DXBuffer *errors = 0;
	HR(D3DXCreateEffectFromFile(gd3dDevice, L"../src/chap14/XFileDemo/PhongDirLtTex.fx",
		0, 0, D3DXSHADER_DEBUG, 0, &mFX, &errors));
	if (errors)
		MessageBoxA(0, (char*)errors->GetBufferPointer(), 0, 0);

	mhTech          = mFX->GetTechniqueByName("PhongDirLtTexTech");
	mhWVP           = mFX->GetParameterByName(0, "gWVP");
	mhWorldInvTrans = mFX->GetParameterByName(0, "gWorldInvTrans");
	mhMtrl          = mFX->GetParameterByName(0, "gMtrl");
	mhLight         = mFX->GetParameterByName(0, "gLight");
	mhEyePos        = mFX->GetParameterByName(0, "gEyePosW");
	mhWorld         = mFX->GetParameterByName(0, "gWorld");
	mhTex           = mFX->GetParameterByName(0, "gTex");
}