Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What should I do if I want to draw 2D lines? I just want to draw nice looking, efficient 2D lines. I am aware there are many high level engines and libraries that let you draw lines, but I have tried them all over many years and they are all bad. This is a serious plea - please help.


On Windows, the best way is often Direct2D https://docs.microsoft.com/en-us/windows/win32/direct2d/dire...

On Linux, you have to do that yourself. The best approach depends on requirements and target hardware.

The simplest case is when your lines are straight segments or polylines of them, you have decent GPU, and you don’t have weird requirements about line caps and joins. In that case, simply render a quad per segment, using 8x or 16x MSAA. Quality-wise, the results at these MSAA levels are surprisingly good. Performance-wise, modern PC-class GPUs (including thin laptops and CPU-integrated graphics in them) are usually OK at that use case even with 16x MSAA.

If MSAA is too slow on your hardware but you still want good quality AA, it’s harder to achieve but still doable. Here’s a relevant documentation from my graphics library for Raspberry Pi4: https://github.com/Const-me/Vrmac/blob/master/Vrmac/Draw/VAA...

Update: if you only need to support nVidia GPUs, they have a proprietary GL extension nv_path_renreding which does pretty much the same thing as Direct2D, but not exclusive to Windows.


Thank you!


Check out my free open source book "A bitmappers companion" its a reference book about 2d graphics algorithms with code examples in Rust. https://github.com/epilys/bitmappers-companion


Thanks!


Have you tried SDL2? I’ve used it in the past for 2d stuff and didn’t have any problems with it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: