Sign in to follow this  
Tumain

City Generation: Vertex/Index Buffer Problems

Recommended Posts

At the moment I am banging my head as to why my geometry is not rendering properly. I do expect its to do with my DrawPrimitive calls and I have looked at other threads with similar problems, however none of them have helped me as of yet.

I have created two different demos both used to generate a city, using different methods.

One just uses one index buffer and one vertex buffer. I intended to test each building for visibility in this demonstration for frustum clipping rather than subgrids.

The problem with this one is that not all geometry is drawn that is in the vertex buffer. This is the code for rendering:


int index = 0;
for (int i = 0; i < m_pBuildings.size(); i++)
{
D3DXMatrixIdentity(&m);
pos = m_pBuildings[i]->GetPosition();
D3DXMatrixTranslation(&m, pos.x, pos.y, pos.z);
gd3dDevice->SetTransform(D3DTS_WORLD, &m);
HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, index, 0, 24, 0, 12));
index += 24;
}



When I use 0 for the index value instead, all geometry is rendered however they are all the same size since they're using the same set of indices/verts.

This is the vertex and index buffer creation code incase there is something wrong there.

http://pastebin.com/9vMi26rK

The other uses multiple index buffers and one vertex buffer. It uses multiple index buffers since I divided the terrain into subgrids to test for collision against the view frustum for view frustum clipping.


int buildingCount = 0;
int index = 0;
int renderingCount = 0;

for (int i = 0; i < m_pSubGrids.size(); i++)
{
buildingCount = m_pSubGrids[i]->count;

if (m_pCamera->IsVisible(m_pSubGrids[i]->AABB))
{
HR(gd3dDevice->SetIndices(m_pSubGrids[i]->IB));

HR(gd3dDevice->SetTransform(D3DTS_WORLD, &m_pCamera->GetWorldMatrix()));
HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, index, 0, 24 * buildingCount, 0, 12 * buildingCount));
renderingCount += buildingCount;
}

index += buildingCount * VERTS_CUBE;
}



This shows all geometry fine, however messes up when the frustum tests to see what subgrids are visible. At certain camera angles certain subgrids will have some geometry disappear. This is weird since I display the amount of buildings that should be rendered depending on the camera angle and it is always right.

In this instance, it makes me believe that something is wrong with my assigning of indices to verts when making the index buffer, but I am unsure.

The vertex and index buffer creation is here:
http://pastebin.com/QdNbyJtG

Any help would be greatly appreciated. In the pastebin links there are VERTS_CUBE and INDICES_CUBE. VERTS_CUBE = 24 and INDICES_CUBE = 36.

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