• Advertisement
Sign in to follow this  

Using D3DPT_LINELIST

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

I've got some code that renders some triangle lists in 3D. Here is my vertex declaration:

D3DVERTEXELEMENT9 BasicMeshVertices[] = {
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{1, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
{1, 16, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
{1, 32, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2},
{1, 48, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 3},
{1, 64, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
D3DDECL_END()
};


I use the code to pass the world matrix and colour to the shader per instance. This code works exactly how it should. However, when I attempt to use this to render a series of 3D lines using D3DPT_LINELIST, the D3D Debug Runtime tells me that my vertex declaration is wrong. I have a shader that works fine with this vertex input for the triangle list. Any suggestions as to what the problem could be? Here is my sample Draw code. The LineVerts are a simple {0, 0, 0} and {1, 0, 0} to represent a unit line on the X axis, and the indices are a simple {0, 1}.


D3DCALL(device->SetVertexDeclaration(VertexDecl));
D3DCALL(device->SetStreamSource(1, PerBoneBuffer.get(), 0, sizeof(PerInstanceData)));
D3DCALL(device->SetStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1));
D3DCALL(device->SetStreamSource(0, LineVerts, 0, sizeof(D3DXVECTOR3)));
D3DCALL(device->SetStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | lines.size()));
D3DCALL(device->SetIndices(LineIndices));
PerInstanceData* data;
std::vector<Wide::Render::Line*> lines_vec(lines.begin(), lines.end());
D3DCALL(PerBoneBuffer->Lock(0, lines.size() * sizeof(PerInstanceData), reinterpret_cast<void**>(&data), D3DLOCK_DISCARD));
std::for_each(lines.begin(), lines.end(), [&](Wide::Render::Line* ptr) {
data->Color = D3DXColor(ptr->Colour);
D3DXMATRIXA16 Translate, Scale, Rotate;
D3DXMatrixTranslation(&Translate, ptr->Start.x, ptr->Start.y, ptr->Start.z);
D3DXMatrixScaling(&Scale, ptr->Scale, 1, 1);
D3DXMatrixRotationQuaternion(&Rotate, &D3DQuaternion(ptr->Rotation));
data->World = Scale * Rotate * Translate;
});
D3DCALL(PerBoneBuffer->Unlock());
D3DCALL(device->DrawIndexedPrimitive(D3DPRIMITIVETYPE::D3DPT_LINELIST, 0, 0, 2, 0, 1));

Share this post


Link to post
Share on other sites
Advertisement
Turns out that I forgot to set the shader to the device when drawing- a silly error.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement