Question

I'm using Direct3D 9 to draw lines.

The vertices I am using now have the format D3DFVF_XYZ|D3DFVF_DIFFUSE and are stored in a vertex buffer. They are drawn with DrawPrimitive as D3DPT_LINELIST.

How do I change the drawn color of a the whole drawn vertex buffer or even a specific vertex without locking the vertex buffer to modify it's content? This has to be done every frame.

Is this possible with a vertex buffer? I would prefer a solution without a custom shader (using the default direct3d 9 pipeline).

If this is not possible, what would be the next best thing to do performance wise? I can only think of locking the vertex buffer or using DrawPrimitiveUP. Both are pretty terrible performance wise.


Updated with solution code:

m_pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_CONSTANT);
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CONSTANT);
m_pDevice->SetTextureStageState(0, D3DTSS_CONSTANT, D3DCOLOR_ARGB(120,0,255,0));

The vertices don't need FVF_DIFFUSE anymore.

Was it helpful?

Solution

With the fixed function pipeline you could use SetTextureStageState (doc) to specify a constant color, which should be used with D3DTSS_CONSTANT (doc). With this option you could set a color for the whole drawcall.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top