Advertisement Jump to content
Sign in to follow this  
jamesxli

DX11 Drawing lines with Direct3D11.

This topic is 1865 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 am trying to port a DX9 application (implemented with C# & SlimDX) to DX11. The application basically renders high dimensional data in the 3D space with dot plots, it needs to draw colored lines for coordinate system or similar fixtures. The application used the Line class of the DX9 library, but the Line class seems to have been removed from DX11.  So, my question is: What is the best way to draw lines in the 3D space with DX11?  

 

 

Share this post


Link to post
Share on other sites
Advertisement
Fill the end-points' attributes (position, color) into a vertex buffer. Write a simple shader set to do the vertex calculations you need (projection, or just pass-through) and the pixel shading (likely just writing out the colors). Create the appropriate simple input layout. Bind layout, shader, and vertex buffer. Use non-index draw method to draw the number of vertices you have (lines * 2).

Pretty much conceptually identical to what you'd be doing in GL|ES, if that helps any.

Share this post


Link to post
Share on other sites

Thanks for the response, but what is "GL|ES"?   Do I need to use geometry shader

to generate to triangles from line-ending points?  Some sample code or link

to similar code would be really appreciated.

Share this post


Link to post
Share on other sites

If you want, you can use the PrimitiveBatch class from DirectXTK to draw your lines. It will handle setting up the vertex buffers and shaders for you. It also has full source code, so you can look at how they do it.

Also by "GL|ES", he was referring to OpenGL ES (what you would use on tablets and phones for rendering).

Edited by MJP

Share this post


Link to post
Share on other sites
I would have recommended the toolkit as well, if he wasn't using SlimDX. Unfortunately it doesn't offer such convenience functionality out of the box (neither does vanilla D3D11). As an alternative, have a look at SharpDX which also has - among a lot of other useful stuff - a primitive batch.
 

Do I need to use geometry shader to generate to triangles from line-ending points

 
Not really. Lines are natively supported (primitive topology line lists or strips). Even anti-aliasing is easily enabled.

But yes, for a more fancy look (e.g. round caps) one needs to resort to geometry shaders to extrude lines to quads.

Share this post


Link to post
Share on other sites

I would have recommended the toolkit as well, if he wasn't using SlimDX. 

 

 

Ahh, I missed that. My apologies.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!