Hm... DrawPrimitive is not functioning properly
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
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/d3d/interfaces/idirect3ddevice9/drawprimitive.asp
PrimitiveType
[in] Member of the D3DPRIMITIVETYPE enumerated type, describing the type of primitive to render.
StartVertex
[in] Index of the first vertex to load. Beginning at StartVertex the correct number of vertices will be read out of the vertex buffer.
PrimitiveCount
[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]
PrimitiveType
[in] Member of the D3DPRIMITIVETYPE enumerated type, describing the type of primitive to render.
StartVertex
[in] Index of the first vertex to load. Beginning at StartVertex the correct number of vertices will be read out of the vertex buffer.
PrimitiveCount
[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]
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,
Rados
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,
Rados
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,
Ken
Drunken Hyena
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,
Ken
Drunken Hyena
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement