Jump to content
  • Advertisement
Sign in to follow this  
Swarmer

Quick and easy newb question: backgrounds with .x

This topic is 4333 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

Hi guys. I was playing around with this tutorial: http://www.gamedev.net/reference/articles/article2079.asp I was wondering how to render a background behind the .x model. I can't seem to get them to both display at the same time. If I just render the background, when I press the rotate buttons the background disappears too. Here is pseudocode of my rendering process: - begin the scene - clear everything - render the background texture - update the time and counters (for the .x model) - update the model - move the model* - draw the model** All that does is give me a black screen. *Here is the the model moving function I'm using (taken from the tutorial):
void CModel::Move()
{
	D3DXMatrixIdentity(&matWorld);
	D3DXMatrixIdentity(&matYWorld);
	D3DXMatrixIdentity(&matXWorld);
	D3DXMatrixIdentity(&matZWorld);
	D3DXMatrixIdentity(&matTranslate);
	D3DXMatrixIdentity(&matUp);

	//This makes the model rotate Y
  	D3DXMatrixRotationY( &matYWorld, D3DXToRadian(fAngle1));
	//This makes the model rotate X
  	D3DXMatrixRotationX( &matXWorld, D3DXToRadian(fAngle2));
	//This makes the model rotate Z
	D3DXMatrixRotationZ( &matZWorld, D3DXToRadian(fAngle3));

	//This moves the stuff around
	D3DXMatrixTranslation(&matTranslate, fLeft, fUp, fForward);
	
	matWorld = (matYWorld * matXWorld * matZWorld * matTranslate);
	m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld);

	D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
	m_pd3dDevice->SetTransform( D3DTS_VIEW,	&matView );
}

I find that if I comment out the last line (setTransform on the matView) and don't call the draw function, I can get the background to render but it disappears if I press the rotate key. **Here is the model drawing function I'm using (also from tutorial):
void CModel::Draw()
{

	LPMESHCONTAINER pMesh = m_pFirstMesh;

	//While there is a mesh try to draw it
	while(pMesh)
	{
		//Select the mesh to draw
		LPD3DXMESH pDrawMesh = (pMesh->pSkinInfo)
			? pMesh->pSkinMesh: pMesh->MeshData.pMesh;
		
		//Draw each mesh subset with correct materials and texture
		for (DWORD i = 0; i < pMesh->NumMaterials; ++i)
		{
			m_pd3dDevice->SetMaterial(&pMesh->pMaterials9);
			m_pd3dDevice->SetTexture(0, pMesh->ppTextures);
			pDrawMesh->DrawSubset(i);
		}
		//Go to the next one
		pMesh = (LPMESHCONTAINER)pMesh->pNextMeshContainer;
	}
}

The code to drawing the background is in a big helper class thing from a library I'm using (hge). I didn't write this and I don't understand most of it, but it works (I think there's other related functions, like the one that makes the quad, but I don't think they are relevant):
void CALL HGE_Impl::Gfx_RenderQuad(const hgeQuad *quad)
{
	if(CurPrimType!=HGEPRIM_QUADS || nPrim>=VERTEX_BUFFER_SIZE/HGEPRIM_QUADS || CurTexture!=quad->tex || CurBlendMode!=quad->blend)
	{
		_render_batch();

		CurPrimType=HGEPRIM_QUADS;
		if(CurBlendMode != quad->blend) _SetBlendMode(quad->blend);
		if(quad->tex != CurTexture) {
			pD3DDevice->SetTexture( 0, (LPDIRECT3DTEXTURE9)quad->tex );
			CurTexture = quad->tex;
		}
	}

	memcpy(&VertArray[nPrim*HGEPRIM_QUADS], quad->v, sizeof(hgeVertex)*HGEPRIM_QUADS);
	nPrim++;
}


So... I think my process is wrong. Am I supposed to be rendering it in this order, or am I doing something completely wrong? Thanks for your help. [Edited by - Swarmer on January 30, 2007 3:49:34 PM]

Share this post


Link to post
Share on other sites
Advertisement
If I was about to render a background behind a mesh, I would do something like this.

• Turn off ZWriteEnable to be safe, pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
• Clear the backbuffer
• Render the background with screen aligned quads, ID3DXSprite or IDirect3DDevice9::StretchRect
• Turn on ZWriteEnable again
• Trun on AlphaBlendEnable, pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
• Set DestBlend to 0, pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ ZERO);
• Set SrcBlend to 1, pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
• Render the mesh.

If you are using the effect framework / .fx you could set the states directly on the graphic card instead of through the application.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!