Search code examples
openglclipping

How to render a cross section in opengl


I was trying to get the cross section of a model, using OpenGL. Specifically, I wanted to project the cross-section view onto a 2D plane. (for example, if I were to cut a pipe with zero-thickness and some finite length, perpendicular from top down, my output should be a circle in 2D view).

I understand that glClipPlane() works, but my understanding is that the function slices the model along the plane, rather than projecting the slice. Is there a way to achieve what I want inside OpenGL?


Solution

  • What glClipPlane does, is it just discards any pixels from rendering behind it.

    There is no out-of-the-box way to fill the "insides" of the model, since there is no way to know what should be there, especially if you remember, that OpenGL is just a render monkey that deals with triangles soup. Model composition is a higher level of abstraction that needs to be handled by your app.

    You need to construct the polys that cover the cross-section surface yourself. To do that you might need some libraries that provide 3D boolean operations and surface reconstruction.

    There should be some volumetric 3D rendering APIs out there, alike voxel-based and such, but using those might be a bigger headache.