Sign in to follow this  
Dom_152

Strange Tile Rendering

Recommended Posts

So I have my TILE class and an array TILE Tiles[1000] The Render function in the TILE class looks like so:
int TILE::Render(float x, float y, LPDIRECT3DTEXTURE9 texture)
{
	
	d3ddevice->SetTexture(0, texture);
	D3DXMatrixTranslation(&WorldMat, x, y, 0.0f);
	d3ddevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
	d3ddevice->SetTransform(D3DTS_WORLD, &WorldMat);
	D3DXVec3TransformCoord(&W1, &D3DXVECTOR3(-1.0f, -1.0f, 0.0f), &WorldMat);
	D3DXVec3TransformCoord(&W2, &D3DXVECTOR3(-1.0f, 1.0f, 0.0f), &WorldMat);
	D3DXVec3TransformCoord(&W3, &D3DXVECTOR3(0.0f, -1.0f, 0.0f), &WorldMat);
	D3DXVec3TransformCoord(&W4, &D3DXVECTOR3(0.0f, 1.0f, 0.0f), &WorldMat);

	d3ddevice->SetTexture(0, NULL);
	

	return 1;
}

And in my Render loop I want to draw 3 Tiles so i do this:
d3ddevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
	
	if(FAILED(d3ddevice->BeginScene()))
	{
		MessageBox(NULL, "Error, could not Begin Scene", "LoARender() Error", MB_OK);
		LoADone();
		return 0;
	}
	
	d3ddevice->SetFVF(TileFVF);
	d3ddevice->SetStreamSource(0, TileVb, 0, sizeof(VTile));

	Tiles[0].texture = HUDTex;
	Tiles[0].Render(-2, -4, Tiles[0].texture);
	Tiles[1].texture = TileTex;
	Tiles[1].Render(-1, -2, Tiles[1].texture);
	Tiles[2].texture = PlayerTex;
	Tiles[2].Render(0, 0, Tiles[2].texture);
	
	//Now specify our View Matrix (AKA The Camera)
	//Because the camera is moving it must be in the Render Code
	D3DXMatrixLookAtLH(&ViewMat, &D3DXVECTOR3(player.x, player.y, camz), &D3DXVECTOR3(player.x, player.y, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0));
	d3ddevice->SetTransform(D3DTS_VIEW, &ViewMat);

	d3ddevice->EndScene();

	d3ddevice->Present(NULL, NULL, NULL, NULL);

And so I thought that would render 3 tiles in that order in a diagonal line, however when I come to run my application the order of the tiles is not quite what I expected. The tile at the top of the line is what its supposed to be the HUDTex tile or Tiles[0] however the next one is not Tiles[1] it's Tiles[2] with the Playertex texture and the final one is Tiles[1]. I don't know why it's showing them in this strange order. It also messes up my Tile Picking routine. i think it may have something to do the the World Matrix but I'm not sure. Any help would be most appreciated.

Share this post


Link to post
Share on other sites
And I think I may have to re-write my rendering code as I've found out the way I'm doing it is very uneffective. I was just reading up on using a dynamic Vertex Buffer and it sounds like that would be better.But still any help with the above problem would be helpful :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this