OpenGL contour and creases render

Viewed 68

I want to render the outlines + creases with opengl but it's not going as I wish. Can someone, please help me to solve this problem? So far the outline it's rendered like this.

How it's rendered now

At this moment what I'm doing is: Frist I do this:

GL.Enable(EnableCap.PolygonOffsetFill);
GL.PolygonOffset(0, -1f);
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
GL.DepthFunc(DepthFunction.Lequal);
GL.DrawArrays(PrimitiveType.Triangles, 0, verticesList.Count);
GL.Disable(EnableCap.PolygonOffsetFill);

Then I render again like this:

GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
GL.LineWidth(5f);
GL.DepthFunc(DepthFunction.Less);
GL.DrawArrays(PrimitiveType.Triangles, 0, verticesList.Count);

I want to render those green lines as well:

How I want to render it

The wireframe over the filled shape looks like this:

How the wireframe looks

Thanks in advance!

1 Answers

You cannot achieve this with GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);. The PolygonMode.Line mode does not render the outlines of the mesh, but the outlines of the primitives (triangles). There is no feature that will give you what you want right away. If you want to draw these lines on a solid mesh, you need to disable the depth test and create a separate geometry with Line primitives. You can use the same vertex coordinates for this geometry, but you must draw them in a different order. OpenGL is just a low-level API implemented by the graphics driver that gives you access to the GPU, but it's not a render, game, or CAD engine. You have to implement the engine and you can do it with OpenGL.

Related