Archived

This topic is now archived and is closed to further replies.

PumpkinPieman

DX 8 Rendering problem.

Recommended Posts

Alright I don''t really know why it''s doing this but here''s what the problem is
DWORD CMesh::Render()
{
    if(m_pMesh != NULL)
    {
        for(DWORD i = 0; i < m_dwNumMaterials; i++)
        {
            m_pD3DDevice->SetMaterial(&m_pMeshMaterials[i]);
            m_pD3DDevice->SetTexture(0, m_pMeshTextures[i]);
        
            m_pMesh->DrawSubset(i);
        }

        return m_pMesh->GetNumFaces();
    }
    else
    {
        return 0;
    }
}
	D3DXMATRIX trans_matrix;
	D3DXMATRIX rotat_matrix;
	D3DXMATRIX matWorld;

	D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER , D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
	//D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0 );

	if(SUCCEEDED(D3DDevice->BeginScene()))
	{
      D3DDevice->SetVertexShader(D3D8T_CUSTOMVERTEX);
      D3DDevice->SetStreamSource(0,D3DVertexBuffer,sizeof(vertex));

	  

	  D3DXMatrixRotationYawPitchRoll(&rotat_matrix,  0.0f,CameraRotY, 0.0f);
      //D3DXMatrixScaling(&scale_matrix, 0.5f, 0.5f, 0.5f);

	  D3DDevice->SetTexture( 0, D3DTexture );
	  float PosX, PosZ;
	  for(int DimX = 0; DimX < 2; DimX++)
	  {
		  for(int DimY = 0; DimY < 2; DimY++)
		  {
			  
			  
			  PosX = 1.5*DimX;
              PosZ = -1.73205*DimY;
			  if(DimX%2 == 1)
                  PosZ += .866025;
              D3DXMatrixTranslation(&trans_matrix,PosX,0.0f, PosZ);
			  D3DXMatrixMultiply(&matWorld, &trans_matrix, &rotat_matrix);
              D3DDevice->SetTransform(D3DTS_WORLD,&matWorld );
              D3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,0,6);
              
		  }
	 }
	  Rung->Render();
	  D3DDevice->SetTexture( 0, NULL );
      D3DDevice->EndScene();

	}

	D3DDevice->Present(NULL, NULL, NULL, NULL);
With the mesh (rung) after the for loop
	D3DXMATRIX trans_matrix;
	D3DXMATRIX rotat_matrix;
	D3DXMATRIX matWorld;

	D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER , D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
	//D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0 );

	if(SUCCEEDED(D3DDevice->BeginScene()))
	{
      D3DDevice->SetVertexShader(D3D8T_CUSTOMVERTEX);
      D3DDevice->SetStreamSource(0,D3DVertexBuffer,sizeof(vertex));

	  

	  D3DXMatrixRotationYawPitchRoll(&rotat_matrix,  0.0f,CameraRotY, 0.0f);
      //D3DXMatrixScaling(&scale_matrix, 0.5f, 0.5f, 0.5f);

	  
	  float PosX, PosZ;
	  for(int DimX = 0; DimX < 2; DimX++)
	  {
		  for(int DimY = 0; DimY < 2; DimY++)
		  {
			  Rung->Render();

			  D3DDevice->SetTexture( 0, D3DTexture );

			  PosX = 1.5*DimX;
              PosZ = -1.73205*DimY;
			  if(DimX%2 == 1)
                  PosZ += .866025;
              D3DXMatrixTranslation(&trans_matrix,PosX,0.0f, PosZ);
			  D3DXMatrixMultiply(&matWorld, &trans_matrix, &rotat_matrix);
              D3DDevice->SetTransform(D3DTS_WORLD,&matWorld );
              D3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,0,6);
              
		  }
	 }
	  
	  D3DDevice->SetTexture( 0, NULL );
      D3DDevice->EndScene();

	}

	D3DDevice->Present(NULL, NULL, NULL, NULL);
This is with the rung in the loop (which should change the location of the new rung). I moved the texture thing in because I assumed that after it renders the mesh it does change the texture back to the one the rest are using. Here''s this one Anyone know what I''m doing wrong? Thanks
Pumpkin Pieman - [Blogger]

Go to war again, blood is freedom''s stain, But don''t you pray for my soul anymore.

Share this post


Link to post
Share on other sites
It only seems to work when I render the hexagons ( non-models ) and the meshs in seperate loops. Anyone know the reason for this?

D3DXMATRIX HexLoc(int x, int y, int z)
{
float PosX, PosY, PosZ;
D3DXMATRIX HexTrans;

PosX = float(1.5*x);
PosY = float(-1.0*y);
PosZ = float(-1.73205*z);
if(x%2 == 1)
PosZ += float(.866025);
D3DXMatrixTranslation(&HexTrans, PosX, PosY, PosZ);
return HexTrans;
}

void render(void)
{
D3DXMATRIX trans_matrix;
D3DXMATRIX rotat_matrix;
D3DXMATRIX matWorld;

D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER , D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
//D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0 );

if(SUCCEEDED(D3DDevice->BeginScene()))
{
D3DDevice->SetVertexShader(D3D8T_CUSTOMVERTEX);
D3DDevice->SetStreamSource(0,D3DVertexBuffer,sizeof(vertex));



D3DXMatrixRotationYawPitchRoll(&rotat_matrix, 0.0f,CameraRotY, 0.0f);
//D3DXMatrixScaling(&scale_matrix, 0.5f, 0.5f, 0.5f);


for(int DimX = 0; DimX < 2; DimX++)
{
for(int DimY = 0; DimY < 2; DimY++)
{

D3DXMatrixMultiply(&matWorld, &HexLoc(DimX, 0, DimY), &rotat_matrix);
D3DDevice->SetTransform(D3DTS_WORLD,&matWorld );
D3DDevice->SetTexture( 0, D3DTexture );
D3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,0,6);

}
}
for(int DimX = 0; DimX < 2; DimX++)
{
for(int DimY = 0; DimY < 2; DimY++)
{
D3DXMatrixMultiply(&matWorld, &HexLoc(DimX, 0, DimY), &rotat_matrix);
D3DDevice->SetTransform(D3DTS_WORLD,&matWorld );
Rung->Render();
}
}
D3DDevice->SetTexture( 0, NULL );
D3DDevice->EndScene();

}

D3DDevice->Present(NULL, NULL, NULL, NULL);
}

Share this post


Link to post
Share on other sites