Jump to content
  • Advertisement
Sign in to follow this  

Strange Tile Rendering

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

If you intended to correct an error in the post then please contact us.

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);
		MessageBox(NULL, "Error, could not Begin Scene", "LoARender() Error", MB_OK);
		return 0;
	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->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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!