OT: a modern line drawing library (for OpenGL)

Skip to first unread message

Gonzalo Garramuño

May 9, 2023, 9:27:54 AMMay 9
to fltkg...@googlegroups.com
Hi.  Sorry for the off-topic, but since there are a lot of people that
know about graphics, I thought I might ask.  I am trying not to reinvent
the wheel.  I am looking to simulate freehand drawing of thick lines
with feathering in opengl for my viewer.

I am looking for a lightweight library (or a class or set of functions)
that would allow me to, given an arbitrary list of points that make a
freehand drawn line, return the vertices of the line drawn with
triangles with UVs (between 0,1 in the width of the line and in the
length of the line).  The idea is that then I would render the triangles
with opengl and would use the UVs in a shader to create a feathering effect.

So far, I found:


The code is messy and it does not use UVs only colors to create
feathering, drawing more than 6 triangles per line segment (slow). 
Other than that, this is closer to what I want.


It has a really neat polyline drawing code, albeit it is too dependent
on several classes in OpenRV itself.


i did not play much with it. It does not allow me to get the list of
points or the UVs but instead just draws the lines in opengl directly. 
I prefer to control the drawing, specially since I am working with
OpenGL3 and drawing to a FBO.  This looks like I could modify it to
make  it work like what I want, but I am not too crazy about its API for
drawing lines.

Gonzalo Garramuño

Matthias Melcher

May 10, 2023, 3:59:54 AMMay 10
to fltk.general
I ended up implementing is myself for some task decades ago. I needed lots of additional functionality that OpenGL would not deliver back then. So I rendered pixel by pixel into a buffer and composited drawn lines using the alpha channel. In today's world, pixel shaders are a great way to achieve all kinds of wonderful effects. Sorry that I can't point you to a library except OpenGL itself.

Gonzalo Garramuño

May 10, 2023, 2:01:05 PMMay 10
to 'Matthias Melcher' via fltk.general

El 10/5/23 a las 04:59, 'Matthias Melcher' via fltk.general escribió:
> I ended up implementing is myself for some task decades ago.

I ended up doing that too, based on template code from Marius Metzger
which did not have support for UVs, but I managed to add it to it.  I
still need to clean it up, because it is a mess right now :D

I tried the other approaches, too.  vaserenderer was inefficient, OpenRV
did not handle closed shapes and did way more than I needed, nanovg did
not handle transparency properly and had a 3x2 transposed matrix that I
could not figure out how to transfer transformations from a standard 4x4
matrix.  nanovg was also the most problematic as it meant changing the
gl render context engine I was using and having to use its own, as it
did not spit out the vertices and uvs (it was a closed box).

Gonzalo Garramuño

Reply all
Reply to author
0 new messages