Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Problem with DrawIndexedPrimitive


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Hawkblood   Members   -  Reputation: 725

Like
0Likes
Like

Posted 09 February 2013 - 05:01 AM

I have two different scenes that are put together at the end. The first scene is the interior of my ship and the second is some terrain. The ship is a mesh rendered with Evolved's Normal mapping with multiple lights. The terrain is a triangle list rendered with DrawIndexedPrimitive. The problem is that the ship's interior doesn't render correctly. It only works correctly if I don't render the terrain (at all). Even when I had a condition to stop rendering the terrain, the ship's interior still had the same issue. Here is an image and the relevant code:

The terrain code:

void TERRAINSTRUCT::Show(GAMEENGINE *GE){
	D3DXMATRIX pm;
	D3DXMatrixPerspectiveFovLH(&pm, 
					D3DX_PI/4.0f,    // the horizontal field of view 
					SCREEN_WIDTH / SCREEN_HEIGHT, // aspect ratio 
					0.5f,    // the near view-plane 
					20000);    // the far view-plane 
	GE->d3ddev->SetTransform(D3DTS_PROJECTION, &pm);

	GE->d3ddev->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_RGBA (105,105,105,105) );
	GE->d3ddev->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_CURRENT );        
	GE->d3ddev->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_TEXTURE );        
	GE->d3ddev->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE2X );
	//do range0
	GE->d3ddev->SetMaterial(&DefaultMatl);
	GE->d3ddev->SetFVF(T_D3DFVF_CUSTOMVERTEX);
	for (int z=0;z<25;z++){
		for (int x=0;x<25;x++){

			if (Range0_1Index[x][z].type==0){//range0
				int i=Range0_1Index[x][z].index;
				D3DXMATRIX wm;
				D3DXMatrixIdentity(&wm);
				wm(3,0)=(float(x)-12.5f)*10.0f;
				wm(3,1)=-1.83f;
				wm(3,2)=(float(z)-12.5f)*10.0f;
				GE->d3ddev->SetTransform(D3DTS_WORLD,&wm);
				GE->d3ddev->SetTexture(0,TextureList[5].Texture);
				GE->d3ddev->SetTexture(1,TextureList[DetailImage].Texture);


				GE->d3ddev->SetStreamSource(0, Range0[i].pVertexObject, 0, sizeof(T_D3DVERTEX));
				GE->d3ddev->SetIndices(Range0[i].i_buffer);
				GE->d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 121, 0, 100*2);
			}

			if (Range0_1Index[x][z].type==1){//range1
				int i=Range0_1Index[x][z].index;
				D3DXMATRIX wm;
				D3DXMatrixIdentity(&wm);
				wm(3,0)=(float(x)-12.5f)*10.0f;
				wm(3,1)=-1.83f;
				wm(3,2)=(float(z)-12.5f)*10.0f;
				GE->d3ddev->SetTransform(D3DTS_WORLD,&wm);
				GE->d3ddev->SetTexture(0,TextureList[5].Texture);
				GE->d3ddev->SetTexture(1,TextureList[DetailImage].Texture);


				GE->d3ddev->SetStreamSource(0, Range1[i].pVertexObject, 0, sizeof(T_D3DVERTEX));
				GE->d3ddev->SetIndices(Range1[i].i_buffer);
				GE->d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 25, 0, 16*2);
			}

		}
	}

	GE->d3ddev->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
	GE->d3ddev->SetTexture(1,NULL);
	GE->d3ddev->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_RGBA (15,15,15,15) );
}

And here is the ship interior code:

void GAMEENGINE::RenderShipInt(){
	d3ddev->SetRenderTarget(0,fpRenderSurf);
	D3DXMatrixPerspectiveFovLH(&MyCamera.m_projMatrix, 
						   D3DX_PI/4.0f,    // the horizontal field of view 
						   SCREEN_WIDTH / SCREEN_HEIGHT, // aspect ratio 
						   0.5f,    // the near view-plane 
						   20000);    // the far view-plane 

	d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE,false);
	d3ddev->SetRenderState(D3DRS_ZWRITEENABLE, true);
	d3ddev->Clear(0,
                           NULL,
                           D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
                           D3DCOLOR_ARGB(0,0,255,0),
                           1.0f,
                           0);
	d3ddev->BeginScene();
	d3ddev->SetTransform(D3DTS_PROJECTION, &MyCamera.m_projMatrix);



	D3DXMATRIX tmp;
	D3DXMatrixIdentity(&tmp);
//	tmp=MyCamera.RotationMatrix;
	tmp(3,0)-=MyCamera.fpPosition.x;
	tmp(3,1)-=23;//MyCamera.fpPosition.y; 23
	tmp(3,2)-=MyCamera.fpPosition.z;

	FXManager.Effect[NormalMappingFX].FX->BeginParameterBlock();
	D3DXVECTOR4 v4( 0.1f, 0.1f, 0.1f, 0 );
	FXManager.Effect[NormalMappingFX].FX->SetVector("Ambient",&v4);

	v4=D3DXVECTOR4(-MyCamera.fpPosition.x,0,-MyCamera.fpPosition.z,0);

	FXManager.Effect[NormalMappingFX].FX->SetVector("LightPosition_1",&v4);
	v4=D3DXVECTOR4(0.35f,0.3f,0.25f,0);
	FXManager.Effect[NormalMappingFX].FX->SetVector("LightColor_1",&v4);
	FXManager.Effect[NormalMappingFX].FX->SetFloat("LightRange_1",10);
	FXManager.Effect[NormalMappingFX].FX->SetTechnique("Light1");
	FXManager.Effect[NormalMappingFX].FX->SetTexture("BaseTX",TextureList[ShipTexture[1].C].Texture);
//	FXManager.Effect[NormalMappingFX].FX->SetTexture("NormalTX",TextureList[ShipTexture[1].N].Texture);
	FXManager.Effect[NormalMappingFX].FX->SetTexture("NormalTX",TextureList[6].Texture);
	D3DXMATRIX wvp=tmp*MyCamera.m_fpViewMat*MyCamera.m_projMatrix;
	FXManager.Effect[NormalMappingFX].FX->SetMatrix("WorldVP",&wvp);
	FXManager.Effect[NormalMappingFX].FX->SetMatrix("World",&tmp);
	FXManager.Effect[NormalMappingFX].FX->SetMatrix("ViewInv",&(MyCamera.fpRotationMatrix*MyCamera.RotationMatrix));
	D3DXHANDLE H=FXManager.Effect[NormalMappingFX].FX->EndParameterBlock();
	FXManager.Effect[NormalMappingFX].FX->ApplyParameterBlock(H);
	UINT cPasses;
	FXManager.Effect[NormalMappingFX].FX->Begin(&cPasses,0);
//	d3ddev->SetTransform(D3DTS_WORLD,&tmp); don't need this
	for (UINT iPass = 0; iPass < cPasses; iPass++)
	{
		FXManager.Effect[NormalMappingFX].FX->BeginPass(iPass);

		MeshObject[ShipInt].ppMesh->DrawSubset(0);

		FXManager.Effect[NormalMappingFX].FX->EndPass();
	}
	FXManager.Effect[NormalMappingFX].FX->End();


	d3ddev->EndScene();
}

They both work just fine except that the ship's interior doesn't show the lighting properly.

 

By the way, when I take out the "DrawIndexedPrimitive" lines, the ship's interior renders fine......

Attached Thumbnails

  • Untitled.png

Edited by Hawkblood, 09 February 2013 - 05:04 AM.


Sponsor:

#2 Hawkblood   Members   -  Reputation: 725

Like
0Likes
Like

Posted 10 February 2013 - 11:09 AM

Ok. I figured out what is causing it. Well, I think I did..... My terrain has 2 tex coordinate sets (tu,tv). One for the base texture and the other for the detail. When I set the "detail" tu,tv pair to 0,0 the ship interior renders correctly, but the terrain of course doesn't..... I wish someone would help me.sad.png

 

Here is my FVF info:

 

struct T_D3DVERTEX {float x, y, z; float nx,ny,nz; float tu1,tv1; float tu2,tv2;};
 

#define T_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX2)


 


Edited by Hawkblood, 10 February 2013 - 11:12 AM.


#3 Hawkblood   Members   -  Reputation: 725

Like
0Likes
Like

Posted 13 February 2013 - 08:33 AM

I really need help solving this......

 

I found an effect that will allow me to do detail, but using it kills the lighting for the terrain. If I knew how to write it I would add lighting to the effect..... Sadly I don't know enough to do this.sad.png






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS