Jump to content
  • Advertisement
Sign in to follow this  
Tumain

City Generation: Vertex/Index Buffer Problems

This topic is 2840 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

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->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->count;

if (m_pCamera->IsVisible(m_pSubGrids->AABB))
{
HR(gd3dDevice->SetIndices(m_pSubGrids->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
Advertisement
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!