Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thick lines in GLUP #54

Closed
BrunoLevy opened this issue Dec 15, 2022 · 11 comments
Closed

Thick lines in GLUP #54

BrunoLevy opened this issue Dec 15, 2022 · 11 comments
Labels
enhancement New feature or request geogram_gfx

Comments

@BrunoLevy
Copy link
Owner

I miss glLineWidth() ...
Need to write a geometry shader or something to be able to draw thick lines.

@BrunoLevy BrunoLevy added the enhancement New feature or request label Dec 15, 2022
@sebmestrallet
Copy link
Contributor

Is there any workaround ?
glupSetMeshWidth() works well to display mesh wireframes of variable width in Vorpaview, but I didn't manage to use it on custom lines. Is this related ?

@BrunoLevy
Copy link
Owner Author

I guess yes, what do you mean by "custom lines" ?
The problem is that glLineWidth() is now deprecated in OpenGL, so if we want thick line primitives, we need to write a special shader that transforms each little segment into a GL_QUAD, transform the vertices and fill-in the GL_QUAD. It will require a geometry shader, and geometry shaders are not available on all plaforms, it is really a pain, this is why I have not implemented yet.
We do not have the problem for drawing the mesh in surfacic primitives, because we are cheating (the fragment shader draws the mesh by changing pixel color in surfacic primitives).

@sebmestrallet
Copy link
Contributor

I naively added this function in my MeshGfx, by looking at how mesh wireframes were drawn:

void CustomMeshGfx::draw_custom_edges() {
      for(/* each group of edges */) {
            glupSetMeshWidth(/* width */);
            glupSetColor4fv(GLUP_FRONT_COLOR, /* color of this group */);
            glupBegin(GLUP_LINES);
            for(/* each edge in this group */) {
                glupPrivateVertex3dv(/* 1st point coordinates */);
                glupPrivateVertex3dv(/* 2nd point coordinates */);
            }
            glupEnd();
      }
}

Thank you for the answer, I do not know anything about OpenGL and did not notice the cheat for surfacic primitives!

@BrunoLevy
Copy link
Owner Author

Yes, I confirm, it corresponds to what I mentioned.
One day I may implement it (but it is a big amount of work, so I cannot promise when).

@BrunoLevy
Copy link
Owner Author

As a workaround, you may draw the same edges several times, and shift the transform matrix a little bit each time.

@BrunoLevy
Copy link
Owner Author

BrunoLevy commented Dec 26, 2023

  • Thick likes support in GLUP_GLSL profile (OpenGL 1.4 and OpenGL 4.4). Works with both immediate and array modes (uses a geometry shader that transforms GL_LINES into little rectangles)
  • Implement in GLUP_ES profile (Macs, Android, WebGL). It will only work in immediate mode (we do not have geometry shaders in this profile).
  • Fragment shader that draw disks at each line extremity for having not too crappy joints
  • Seems that it does not work under Windows, to be tested (and fixed !)
  • double test with Nico's Windows machine that seems to behave differently
  • test on Mac (Laurent)
  • High quality rendering by raytracing capsules (not sure I'll do that...)

@sebmestrallet
Copy link
Contributor

Congratulations on making it happen! 🤩 I tested it separately on the last commit of the main branch.

Be able to use it on my work project would be awesome! Do you think the main branch is stable enough? Is a new release in preparation?

@BrunoLevy
Copy link
Owner Author

Next release will be published soon, but I have a couple of things to finish in the mesh intersection / boolean ops before shipping it (cannot say exactly when it will be done)

If you are impatient, I keep the main branch quite stable, you can check the status of the continuous builds and the nighty builds (if it is all green, there are good chances you won't have too many problem updating).

@BrunoLevy BrunoLevy reopened this Jan 31, 2024
@BrunoLevy
Copy link
Owner Author

Reopened issue because it does not work very well under Windows as observed by Nicolas Ray.

@BrunoLevy
Copy link
Owner Author

BrunoLevy commented Feb 3, 2024

On Windows, with GLUP_140 and GLUP_440 I get an error:
gl_ClipDistance different type between shaders
Googling around, it seems that the size of the gl_ClipDistance is inferred, deduced by how it is accessed in the shader, and maybe the inferred value is different in different stages ?

@BrunoLevy
Copy link
Owner Author

Fixed problem under windows:
The problem was that both the vertex and geometry shader were writing to gl_ClipDistance, which is supposed to be an error (the error was not detected by the NVidia Linux driver).
Pushed the fix plus some code that save all the generated shaders to files when gfx:gl_Debug is set (it is how I figured out what happened, using also glslangValidator to analyze them).
It is because thick lines are both line primitives and surfacic primitives, and the code that writes gl_ClipDistance in the vertex shader does it if it is a line primitive, so I needed also to check that primitive is not GL_THICK_LINES explicitly.
-> pushing a new v1.8.8 release with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request geogram_gfx
Projects
None yet
Development

No branches or pull requests

2 participants