Jump to content
  • Advertisement
Sign in to follow this  
whizkid667

ID3DXRenderToEnvMap

This topic is 4251 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!