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

Recommended Posts

Hi When I load in a .X model, the texture UV coords of all my other objects get messed up (the model displays fine). If I draw the model after drawing the other objects, it works fine EXCEPT the other objects are drawn behind the model, which is not what I want. Any ideas? Tom

Share on other sites
More revelant details might be useful [wink]

As a general point, if one set of rendering causes other rendering to work incorrectly you are almost certainly "leaking" state and/or relying on default values that are no longer the default you thought they were.

Without more information on how you're storing/rendering your .x mesh it's difficult to say with any accuracy what you might be messing up. Shaders, vertex declarations etc... if using effect files, make sure you EndPass() and End() accordingly.

hth
Jack

Share on other sites
I am using a framework I have been given. Here is the part which draws the mesh (the problem only occurs when this method is called):

void DisplayMesh(Mesh PassedMesh){	D3DXMATRIX rot_matrixx;	D3DXMATRIX rot_matrixy;	D3DXMATRIX rot_matrix;	D3DXMATRIX trans_matrix;	D3DXMatrixRotationY(&rot_matrixy,PassedMesh.roty);	D3DXMatrixRotationX(&rot_matrixx,PassedMesh.rotx);	D3DXMatrixMultiply(&rot_matrix,&rot_matrixx,&rot_matrixy);	D3DXMatrixTranslation(&trans_matrix,PassedMesh.posx  ,PassedMesh.posy ,PassedMesh.posz);	D3DXMatrixMultiply(&DX_structure.MatrixWorld,&rot_matrix,&trans_matrix);	DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );	for( DWORD i=0; i<PassedMesh.g_dwNumMaterials; i++ )    {		DX_structure.D3DDevice->SetMaterial( &PassedMesh.g_pMeshMaterials );        DX_structure.D3DDevice->SetTexture( 0, PassedMesh.g_pMeshTextures );        PassedMesh.g_pMesh->DrawSubset( i );    }}

Here is the part which draws the other objects:

void DisplayItem()	{		D3DXMATRIX rot_matrixx;		D3DXMATRIX rot_matrixy;		D3DXMATRIX rot_matrixz;		D3DXMATRIX rot_matrix;		D3DXMATRIX rot_matrix2;		D3DXMATRIX trans_matrix;		DX_structure.D3DDevice->SetStreamSource( 0, sprite, 0, sizeof(CUSTOMVERTEX) );		if (!ShowOnScreen)			return;				DX_structure.D3DDevice->SetRenderState( D3DRS_ZENABLE, FALSE );					D3DXMatrixRotationY(&rot_matrixy,rotY);		D3DXMatrixRotationX(&rot_matrixx,rotX);		D3DXMatrixRotationZ(&rot_matrixz,rotZ);		D3DXMatrixMultiply(&rot_matrix2,&rot_matrixx,&rot_matrixy);		D3DXMatrixMultiply(&rot_matrix,&rot_matrix2,&rot_matrixz);		D3DXMatrixTranslation(&trans_matrix, positionX, positionY, positionZ);		D3DXMatrixMultiply(&DX_structure.MatrixWorld,&rot_matrix,&trans_matrix);		DX_structure.D3DDevice->SetTransform( D3DTS_WORLD, &DX_structure.MatrixWorld );				...DX_structure.D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );		DX_structure.D3DDevice->SetStreamSource( 0, DX_structure.D3DVBBackDrop, 0, sizeof(CUSTOMVERTEX) );	}

Share on other sites
DisplayMesh() sets the device's material, and DisplayItem() doesn't, therefore it'll pick up whatever the last subset's material was.

But that all depends on what CUSTOMVERTEX is and whether you have lighting enabled that will use the active material.

Try re-setting a default material in DisplayItem() before you submit the draw call.

hth
Jack

Share on other sites
I'm still having problems with it. It's caused by the DrawSubSet(int) method in directx. If I comment this line out, everything works fine (except the X model is not displayed).

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 12
• 9
• 12
• 37
• 12
• Forum Statistics

• Total Topics
631419
• Total Posts
2999987
×