Search code examples
opengljogllines

OpenGL linestrip boundaries


I have a network of polylines, and I'd like to display all parts of the lines that are inside a certain X-Y box. I'm currently rendering the lines in OpenGL using a GL_LINE_STRIP and it works well. However, if the boundary of the X-Y box crosses through one of the lines (between vertices), is there a good way to just display the part of the line that is inside the box?

thanks,

Jeff


Solution

  • If your box is just a ordinary two-dimensional, axis alined rectangle you can use the glScissor function. In a nutshell it defines a 2D rectangle in screen-coordinates where all drawing takes place.

    If you case is more complicated (e.g. you may have a rectangle on a plane inside a 3D scene or so..) you can first draw your rectangle into the stencil buffer and enable stencil-test for the line-rendering. That approach gives you unlimited flexibility about the shape that restricts the drawing but it may be slightly slower during rendering and takes more effort to setup.