• 14
• 12
• 9
• 10
• 13

Non-FVF vertex buffer

This topic is 4562 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi! I want to create a non-fvf vertex buffer. The DirectX documenatation just says that I have to set the FVF flag of the CreateVertexBuffer method to zero, but it does not say how I can specify the vertex declaration which shall be used for the new vertex buffer. How can I do that? For instance, I have to following array of vertex elements:
D3DVERTEXELEMENT9 vdecl[] = {
{0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0},
{0, 16, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
{0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END()
};

Afterwards I create the vertex declaration:
LPDIRECTION3DVERTEXDECLARATION myVertexDeclaration;
device->CreateVertexDeclaration(vdecl, &myVertexDeclaration);

But how can I tell the CreateVertexBuffer method that it shall use this declaration for the new buffer? Thanks in advance. rgds

Share on other sites
Quote:
 Original post by ChristophRBut how can I tell the CreateVertexBuffer method that it shall use this declaration for the new buffer?

When using Vertex Declarations, you don't tell D3D about the vertex structure until rendering. You don't even use it when you create the VB. So normally, your rendering sequence is something like this:

SetVertexDeclaration()
SetStreamSource()
SetIndices()

DrawIndexedPrimitive()

Share on other sites
Ok, thanks. Now I have got another problem: when I call SetVertexDeclaration before I render my vertexbuffer it returns D3DERR_INVALIDCALL.

D3DVERTEXELEMENT9 decl[] =        {            { 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },            D3DDECL_END()        };	device->CreateVertexDeclaration(decl, &myVertexDeclaration);	device->SetVertexDeclaration(myVertexDeclaration);

But myVertexDeclaration is valid (it is not NULL and CreateVertexDeclaration also returned S_OK).

What could be the reason?