Sign in to follow this  
whizkid667

ID3DXRenderToEnvMap

Recommended Posts

whizkid667    126
Am using ID3DXRenderToEnvMap for real time environment mapping....The problem I am facing is that ID3DXRenderToEnvMap::End() is always returning a FAILED value. I tried changing the parameters D3DXCreateRenderToEnvMap fn but to no avail. Help from any quaters will be truly appreciated. Here's the code:
BOOL cEnvMap::LoadMesh(cCube *pRoom, cCube *pLtBox)
{
	m_pRoom		= pRoom ;
	m_pLtBox	= pLtBox ;

	if(FAILED(D3DXCreateCubeTexture(m_pDevice, TEX_DIMENSION, 0, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &m_pTex)))
	{
		return FALSE ;
	}
	if(FAILED(D3DXCreateRenderToEnvMap(m_pDevice, TEX_DIMENSION, 0, D3DFMT_X8R8G8B8, TRUE, D3DFMT_D24S8, &m_pRenderToEnvMap)))
	{
		return FALSE ;
	}
	return TRUE ;
}

BOOL cEnvMap::RenderSceneIntoEnvMap()
{
	HRESULT			hr ;
	D3DXMATRIX		matProj ;
	D3DXMATRIX		matView ;
	UINT			nIndex ;

	// Set the projection matrix for a field of view of 90 degrees
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI * 0.5f, 1.0f, 0.5f, 1000.0f ) ;
	// Get the current view matrix, to concat it with the cubemap view vectors
	D3DXMATRIX  matViewDir(m_matView) ;
	matViewDir._41 = 0.0f; matViewDir._42 = 0.0f; matViewDir._43 = 0.0f;
	// Render the six cube faces into the environment map
	if(m_pTex)
	{
		hr = m_pRenderToEnvMap->BeginCube(m_pTex) ;
	}
	if(FAILED(hr))
	{
		MessageBox(0, TEXT("Render to EnvMap Failed"), 0, 0) ;
		return FALSE ;
	}
	for(nIndex=0;nIndex<6;nIndex++)
	{
		m_pRenderToEnvMap->Face((D3DCUBEMAP_FACES) nIndex, 0 ) ;
		// Set the view transform for this cubemap surface
		GetCubemapViewMatrix((D3DCUBEMAP_FACES) nIndex, &matView) ;
		D3DXMatrixMultiply(&matView, &matViewDir, &matView) ;
		RenderScene(&matView, &matProj) ;
	}
	if(FAILED(m_pRenderToEnvMap->End(D3DX_FILTER_LINEAR)))
	{
		MessageBox(0, TEXT("End Failed"), 0, 0) ;
		return FALSE ;
	}
	m_pFloor->SetCubeTexture(m_pTex) ;
	return TRUE ;
}
[Edited by - whizkid667 on November 27, 2006 7:13:44 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this