Simplest way to draw line in DirectX 11 (C++)?

10,063

The most common solution would be to use D3D11_PRIMITIVE_TOPOLOGY_LINELIST in your IASetPrimitiveTopology calls.

I suspect (but didn't profile) it is also a pretty fast way of rendering lines. In your comment, you mention the cost of switching the primitive topology setting. I'd say that cost is negligible, as it comes down to one state switch per frame (render primitives first, lines last).

Share:
10,063
PolGraphic
Author by

PolGraphic

I'm a programmer and web designer from Poland.

Updated on June 04, 2022

Comments

  • PolGraphic
    PolGraphic almost 2 years

    I want to draw a line in my DirectX 11 application. I want it to have constant width (not depending on distance from camera), but it has to be a line in space (3D), so something like lines of objects in wireframe mode. I will render my line in a scene full of other objects with some shaders.

    What would be the best and simplest way to achive it in DirectX 11 with C++ (not C#)?

    Code sample will be appreciated ;)

  • Eric Fortier
    Eric Fortier over 8 years
    In a windowed mode, my app ran at 64 FPS according to fraps using a very unoptimized loop (using timers). I was able to push the rendering to 150 fps by inlining multiple calls to Render() during the same render event. Long story short, I had to render over 1800 lines (using linelist) before I would see even the smallest drop in fps. And that's on top of rendering a bitmap and a window full of text. Pretty fast.