Rendering a smooth spline

I’ve got a spline I render like so, given an array of four control points “cpts”:

glEnable( GL_LINE_SMOOTH );
glMap1f(GL_MAP1_VERTEX_3, 0, 1, 3, 4, cpts[0]);
glBegin(GL_LINE_STRIP);
for (int i = 0; i <= 30; i++)
glEvalCoord1f((GLfloat) i/30.0);
glEnd();

Very pretty, but I want to get rid of the jaggies, so I add:

glEnable( GL_BLEND );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

Unfortunately, when I do this, I can see faint “cracks” between the line segments, since with the blending they no longer overlap seamlessly.

Cracks are maybe a little better than jaggies, but I’d prefer neither. Any advice?

Just a nudge to this topic - has nobody run into this problem, or is there no solution?

Try stencil buffer to prevent overlapping

I think glDepthMask(false) will do the trick.

Sorry, the glDepthMask call didn’t seem to do it (I put it up with the glBlend stuff, let me know if it goes somewhere else).

Any place in particular I should go to learn about stencil buffering? I’m off to go do a search now…

(edit) I should perhaps clarify that my problem isn’t overlapping line segments, but rather the opposite of it - GAPS between line segments that only show up with antialiasing enabled. From what I’ve read so far about stencil buffers it doesn’t look like that’ll help this situation…

(yet another edit) This is a simple 2D spline.

[This message has been edited by Samwise415 (edited 01-14-2003).]

Ahhh, so while I was reading about depth buffering, an idea hit me, and I changed my code to run like this:

glMap1f(GL_MAP1_VERTEX_3, 0, 1, 3, 4, cpts[0]);

glBegin(GL_LINE_STRIP);
for (int i = 0; i < 31; i++)
glEvalCoord1f((GLfloat) i/30.0);
glEnd();

glBegin(GL_LINE_STRIP);
for (int i = 0; i < 33; i++)
glEvalCoord1f((GLfloat) i/30.0);
glEnd();

making two passes through the thing, drawing two overlapping splines, but using different numbers of segments so that the cracks don’t overlap.

It doesn’t seem perfect (I might need to fiddle with the numbers of segments), and it seems somehow inefficient to me, but it’s a good starting point.

If anyone has better ideas, please share them.