How to draw vertices in a vertex buffer in another color

谁都会走 提交于 2019-12-24 14:00:24

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/16448206/how-to-draw-vertices-in-a-vertex-buffer-in-another-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!