Jump to content
  • Advertisement


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

Hm... DrawPrimitive is not functioning properly

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

Hi all. I have a problem when I want to render just a part of a vertex buffer. When I call DrawPrimitive( D3DPT_TRIANGLELIST, 1, 2) D3D doesn''t render anything, but if I call DrawPrimitive( D3DPT_TRIANGLELIST, 0, 3) All three triangles are rendered properly. I have no idea where the problem is or how to fix it. I am sure that my vertex buffer is properly created. I think maybe the offset has something to do with this, but i can''t figure out what exactly. I would like to note that I''m using my custom vertex declaration: D3DVERTEXELEMENT9 decl[] = { { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, { 0, 3*sizeof(FLOAT), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, { 0, 6*sizeof(FLOAT), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 }, { 0, 9*sizeof(FLOAT), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() }; And my vertex structure is: struct sVertex { public: FLOAT m_vPos[3]; FLOAT m_vNormal[3]; FLOAT m_vTangent[3]; FLOAT m_vTextureCoord[2]; }; I render the Vertex Buffer like this: m_pD3DDevice->SetVertexDeclaration(m_pVertexDeclaration) m_pD3DDevice->SetStreamSource( 0, m_pVertexBuffer, 0, sizeof(sVertex) ); m_pD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 1, 2); And this is not rendering anything. But, as I said before, if I change the DrawPrimitive to DrawPrimitive( D3DPT_TRIANGLELIST, 0, 3), all three triangles are rendered properly. I am so frustrated... blah... Any help is appreciated!! And I apologize for my bad English Thanks in advance, Rados

Share this post

Link to post
Share on other sites

[in] Member of the D3DPRIMITIVETYPE enumerated type, describing the type of primitive to render.
[in] Index of the first vertex to load. Beginning at StartVertex the correct number of vertices will be read out of the vertex buffer.
[in] Number of primitives to render. The maximum number of primitives allowed is determined by checking the MaxPrimitiveCount member of the D3DCAPS9 structure. PrimitiveCount is the number of primitives as determined by the primitive type. If it is a line list, each primitive has two vertices. If it is a triangle list, each primitive has three vertices.

The index is base 0. Specifying 0 is pointing to the "first" element of the array, while specifying 1 is pointing to the "second" element of the array.

[edited by - Raloth on November 16, 2003 9:12:17 PM]

Share this post

Link to post
Share on other sites
Thanks for the quick reply Raloth.
But I think you didn''t understand my question fully. I know that when I specify 1 that it will start from the "second" element. That is what I want to do. I just want to render the second and third triangle (start at index 1 and render 2). But, if I put that the StartVertex is not 0, the DrawPrimitive doesn''t render anything! I am very confused about that.

Thanks again,

Share this post

Link to post
Share on other sites
StartVertex [in] Index of the first vertex to load

StartVertex is given in terms of vertices, whereas PrimitiveCount is given in terms of primitives. So:
m_pD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 1, 2);

says to draw 2 triangles, but to start reading the vertex buffer from the second vertex in the buffer.

Stay Casual,

Drunken Hyena

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!