# Quick and easy newb question: backgrounds with .x

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

## 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
//This makes the model rotate X
//This makes the model rotate Z

//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)
{
{
_render_batch();

}
}

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 on other sites
There used to be a reply here; where'd it go? Did someone delete it?

##### Share on other sites
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.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 15
• 13
• 9
• 12
• 10
• ### Forum Statistics

• Total Topics
631442
• Total Posts
3000087
×