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]