// before I read in the heightmap and generate
// the vertex buffer
...
// when mapWidth is eg 4, the terrain is three squads wide
// when mapHeight is eg 4, the terrain is three squads tall
unsigned short indexCount = mapWidth * 2 * (mapHeight - 1);
WORD* inds = new WORD[indexCount];
int count = 0;
for (row = 0; row < mapHeight - 1; ++row)
{
// I go over the rows like when lawning the grass.
// On even rows I go from left to right and on odd rows
// I go from the right to the left. This is done to make
// all the strips being attached to each other
if (row % 2 == 0)
{
for (int col = 0; col < mapWidth; ++col)
{
inds[count++] = row * mapWidth + col;
inds[count++] = (row + 1) * mapWidth + col;
}
}
else
{
for (int col = mapWidth - 1; col >= 0; --col)
{
inds[count++] = (row + 1) * mapWidth + col;
inds[count++] = row * mapWidth + col;
}
}
}
// and here we create the index buffer
hRet = device->CreateIndexBuffer(sizeof(WORD) * indexCount, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &ib);
if (FAILED(hRet)) return hRet;
// lock the buffer and copy the data
void *idata;
hRet = ib->Lock(0, 0, (BYTE**)&idata, D3DLOCK_NOSYSLOCK);
if (FAILED(hRet)) return hRet;
memcpy(idata, inds, sizeof(WORD) * indexCount);
ib->Unlock();
delete [] inds;
...
filling in the indexbuffer for rendering terrain with triangle strips
Hello,
I am currently trying to generate an IndexBuffer from a heightmap. First I just read in the heightmap from which every pixel identifies one vertex. All these verts are then stored into a VertexBuffer.
Next, I try to fill in an IndexBuffer to render the terrain with triangle strips. But it seems that there is something wrong, because when I finally render it, it looks like this: wrong terrain
Rendering one row works ok (at least it looks ok). But from the moment I try to render two rows, it seems to miss one squad. Well, I guess the reason is it probably draws two squads at the same position.
Finally, I show you my code for filling in the index buffer down here. I really don''t know what is wrong. I tried to do several things. Like having multiple index buffers and such, but they all give some bizar problems.
Anyway, any help would be appreciated.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement