tags:

views:

157

answers:

2

Hi, 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

+4  A: 

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.

Nils Pipenbrinck
thanks for the quick reply.
Jeff Storey
+1  A: 

I think Nils Pipenbrinck gave you the best two options, but I'll throw out another just for completeness: clip planes (glClipPlane()).

That said, I think glScissor() is the easiest solution if it will always be window aligned.

Drew Hall