1

I am using GL_LINE_STRIP and glLineWidth to draw lines. However, this leads to gaps between the single, straight segments of the strip.

I had mitigated the problem by using Catmull-Rom Splines and thus the segments where smooth enough to not notice the gaps anymore:

100% opacity, graphic card

But now I noticed the gaps are different depending on the OpenGL implementation. Mesa introduces larger gaps than my graphic card, notice the gaps in the upper part and how the lower part with much smaller segments is noticeably darker due to more gaps:

100% opacity, Mesa

Please note that image 1 and 2 are the same render code, the opacity is 255 in both cases, just the used opengl32.dll differs.

I then added the drawing of every joint as point:

glBegin(GL_LINE_STRIP);
for (auto p : interpolatedPoints) {
    glVertex2f(p.x, p.y);
}
glEnd();
glBegin(GL_POINTS);
for (auto p : interpolatedPoints) {
    glVertex2f(p.x, p.y);
}
glEnd();

This works for opacity 255 but not if I want to reduce the objects transparency. What happens then, is that the transparent point overlays the transparent line strip, thus increasing the opacity especially in areas with very short strips:

50% opacity, Filling gaps with points

Solution 1: Polyline quadstrip

Ditching GL_LINE_STRIP altogether and triangulate the line strip ourselves seems the solution here but this looks like a larger rewrite for me - either I need a new shader or I need to calculate the triangles.

Solution 2: Blending

Wanting to avoid the rewrite, I was wondering: can blending solve the issue? Currently I use

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Is there a blending configuration which would prevent the points to add on the alpha channels of the lines? I tried some other constants here but I had no success. Please note also that the black background in the screenshots may not be black at all but contain other objects and textures which should be "correctly" overlayed by the semi-transparent line.

PhilLab
  • 4,777
  • 1
  • 25
  • 77

1 Answers1

0

As a potential easy fix, you could try setting glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) and see if that helps.

If you want your lines to look nice when drawn transparently, I suggest drawing all your lines onto a separate framebuffer than the rest of your scene, reusing the same depth buffer, and with full opacity. Then draw the lines framebuffer onto the rest-of-your-scene framebuffer with partial transparency.

Magma
  • 566
  • 2
  • 8