Archived

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

leedude

rendering a tile based map

Recommended Posts

I was wondering what ppl here thought is the best (or just a ''good'') way to draw a map to the screen that is made up of a series of textured tiles. A little more info should anyone be interested...the map will be viewed from directly overhead, and different tiles will have different textures on them, so its not just the same texture repeated everywhere. My idea at the moment is to make a textured tile class and a map class. The map class will hold an array of these tiles. The tile class will hold info it needs to draw a tile, like a texture, and a vertice for each of the tile corners (so 4 of them), and texture coordinates. Now i was looking for some advice from ppl here that mite have done sthin like this before, coz im worried that this approach may not be that efficient, because a lot of the tiles will be sharing vertices, but i cant put them all into the one vertex buffer can i because many will use different textures. As i see it, this would mean i have to make a seperate vertex buffer for each tile, and then loop thru all my tiles and render them one by one, but i thought i''ve heard that using many small bufferes mite not be a very efficient way of doing things. Does anyone have any pointers on how to layout my map and tiles, and how to draw them efficiently? thanks

Share this post


Link to post
Share on other sites
If you don''t change map every frame, you could group tiles with same texture together and put them in same vertex buffer (so you`ll have as many vertex buffers as you have different textures).

Share this post


Link to post
Share on other sites
thanks for the reply, i''ve been playing around with some stuff, and im having a hard time working with my vertex buffers and drawing things.

i have made the following class to represent a tile to be drawn to screen, but i am not sure if i should put the vertex buffer within the class or just keep the class as a container for my coordinates, and send them to a vertex buffer somewhere in my main rendering code.

#define D3DFVF_D3DVertex (D3DFVF_XYZ|D3DFVF_TEX1)

// Vertex stucture.
struct Vertex
{
float x, y, z; // x, y, and z coordinates.
float tu, tv; // Texture coordinates.
};

class Square
{

public:

Square();
~Square();

Vertex *points;

LPDIRECT3DVERTEXBUFFER9 Vertex_Buffer;
LPDIRECT3DTEXTURE9 Texture;

bool Initialise(LPDIRECT3DDEVICE9 *pDevice, float size);

};

Initialise will calculate the values in ''points'' and create a vertex buffer containing those vertices in ''points''

any thoughts on my completely stupid design are much welcome!

Share this post


Link to post
Share on other sites