Drawing terrain starting from the top left

Started by
15 comments, last by JB3DG 9 years, 10 months ago

The SetVertex and Index buffers part:


CreateBuffers(mvg->dev, &mvg->pVB, &mvg->pIB);
UINT stride = sizeof(VERTS);
UINT offset = 0;
mvg->devcon->IASetVertexBuffers(0, 1, &mvg->pVB, &stride, &offset);
mvg->devcon->IASetIndexBuffer(mvg->pIB, DXGI_FORMAT_R32_UINT, 0);

The input layout:


pFXT = pFX->GetTechniqueByName("RENDER");
if(pFXT)
{
	pFXT->GetDesc(&techDesc);

	D3D11_INPUT_ELEMENT_DESC ied[] = 
	{
		{ "ANCHOR", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};
	D3DX11_PASS_DESC PassDesc;
	pFXT->GetPassByIndex(0)->GetDesc( &PassDesc );
	dev->CreateInputLayout( ied, 1,	PassDesc.pIAInputSignature,	PassDesc.IAInputSignatureSize, &pLayout);
}

the draw call:


mvg->devcon->ClearRenderTargetView( mvg->rtv, D3DXCOLOR(0.0f,0.0f,0.0f,1) );
mvg->devcon->ClearDepthStencilView( mvg->dsv, D3D11_CLEAR_DEPTH, 1.0f, 0 );

mvg->devcon->IASetInputLayout( mvg->pLayout );
mvg->devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

mvg->view->SetMatrix(&vMat.m[0][0]);
mvg->prj->SetMatrix(&pMat.m[0][0]);

for( UINT p = 0; p < mvg->techDesc.Passes; p++ )
{
	//apply technique
	mvg->pFXT->GetPassByIndex( p )->Apply(0, mvg->devcon);	

	//draw billboard
	mvg->devcon->DrawIndexed(38400, 0, 0);
}
Advertisement

3 (mostly unrelated) things concerning your code but essential when using C++:

- you create your temporary vertex and index arrays using new[] so they must be deleted with delete[].

- the loop creating indices goes out of bounds, when z=79 and x=79 : 79 * 80 + 79 + 81 > 6399. In this case the maximum loop count should be 79.

- bd.ByteWidth = sizeof(ind)*38400; I don't know your target system but this line creates different output on x64 and x86, since the pointer size on each platform is different. You should use sizeof(unsigned long) instead.

Cheers!

3 (mostly unrelated) things concerning your code but essential when using C++:

- you create your temporary vertex and index arrays using new[] so they must be deleted with delete[].

- the loop creating indices goes out of bounds, when z=79 and x=79 : 79 * 80 + 79 + 81 > 6399. In this case the maximum loop count should be 79.

- bd.ByteWidth = sizeof(ind)*38400; I don't know your target system but this line creates different output on x64 and x86, since the pointer size on each platform is different. You should use sizeof(unsigned long) instead.

Cheers!

Thanks. Any other ideas regarding the vertex order/positioning?

Any ideas?

Have you tried to simplify your grid? ie. just draw 1x1 size grid and then 2x2 ....

Cheers!

Good point ill try that.

found the cause of the problem. Got assbitten by an extra 32 bytes at the end of the row during the image transfer from GPU to system mem. Everything working now.

This topic is closed to new replies.

Advertisement