Skip to main content
gamedev.net
🔒 Locked

Vertex Buffer Issue

Started by webjeff Aug 7, 2005 at 1:51 PM 3 replies 550+ views
Original Post
webjeff
webjeff
I have a vertex buffer filled, index buffer filled, and when I render the model, it shows up fine... I'm manual parsing this file by the way. edit: Since there are two materials, I split the indicies into two groups, there are 600 faces. when I render like this: m_RenderingDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,m_VertexCount,0,600); //everything shows up fine. When I render like this with 2 calls: m_RenderingDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,m_VertexCount,0,300); m_RenderingDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,m_VertexCount,301,600); I see some of the model and a bunch of missing triangles. Any idea why? By the way, those calls are in loops, I'm resetting the vertex buffer and index buffer etc. But this should render the whole model, I'm just seperating the faces into parts right?? Why is this not working? Thanks a lot Jeff [Edited by - webjeff on August 7, 2005 2:25:35 PM]
Armadon
Armadon
Hi there webjeff,
How are you doing?

[The problem]
When you split up your render calls you are missing some triangles.
[source lang = c++]//everything shows up fine.m_RenderingDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,m_VertexCount,0,600);//This is brokenm_RenderingDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,m_VertexCount,0,300);m_RenderingDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,m_VertexCount,301,600);


[The solution]
Let's look at the call you are invoking.
HRESULT DrawIndexedPrimitive(
D3DPRIMITIVETYPE Type,
INT BaseVertexIndex,
UINT MinIndex,
UINT NumVertices,
UINT StartIndex,
UINT PrimitiveCount
);

1) You are saying there are "there are 600 indicies.".
This does not mean it has 600 primitives.

Example:
a quad has 4 indices but only 2 primitives.

2) Also the 2nd last parameter is the start index. You are specifying that the index is 301, which might be wrong..

3) The last parameter takes the number of primitives to be drawn, not the number of indices :)


[Conclusion]
You might want to take a look at this article.

I hope this helps a bit.
Keep cool
webjeff
webjeff
No you are absolutely correct.

I was typing too fast :). There are 600 faces, not indicies. so I am rendering have the faces. each face contains 3 indicies. Sorry for the confusion.

I will edit the post to make clearer. But I am doing 600 FACES not indicies. Thanks for the mixup. Any other ideas on why that might be wrong?

Thanks
Jeff.
webjeff
webjeff
I found the problem... Just incase you run into the same thing, read the docs closer.

These lines are wrong:
m_RenderingDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,m_VertexCount,0,300);
m_RenderingDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,m_VertexCount,301,600);

should be:
m_RenderingDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,m_VertexCount,0,300);
m_RenderingDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,m_VertexCount,301*3,300);

Notice the *3, its the index start, not the primative start, I was thinking the last two parameters were the same. also, the last param should be the count, not the total.

Those 2 things fixed it.
Drakex
Drakex
Quote:
But I am doing 600 FACES not indicies.


Exactly. You are drawing 300 faces, not indices, meaning 300 faces * 3 indices per face = 900 indices.

Also, in you DIP call, the last parameter is not an "end index" value. It's the number of primitives to draw. So, your calls should be..

m_RenderingDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,m_VertexCount,0,300);m_RenderingDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,m_VertexCount,900,300);


First batch starts at index 0 and draws 300 faces. Each face is 3 indices, so indices 0-899 are used. Then, the second batch begins at index 900 (first undrawn index) and draws the other 300 faces.

Dammit, you figured it out ;)
___________Hoo-rah.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.