Aliasing of filled (tessellated) edges

I’m drawing a rounded rectangles. If I don’t flood fill them with a color (tessellation) the corners are very smooth. When I draw the filled version the corners are jaggy. Here’s a link to the picture: http://www.hindbrain.net/aliasing.png

I’m drawing an unfilled rounded box with a thick line first and then overlaying that with the white-filled rounded box. This picture zooms in on a corner.

How can I get the white box corners to not be so jagged?

thanks,
William

I found a ‘work around’ by drawing another thick white line around the filled shape. It hides the ragged edges with a smooth line of the same color. But it would be nice if there was a more direct solution.

William

You need to enable anti-aliasing for the filled polygon.

How do you smooth the “unfilled” rounded box ? With GL_LINE_SMOOTH ? Then for filled primitives, you should also enable GL_POLYGON_SMOOTH.

Thanks. I just tried that and it does give me smooth corners but it also puts strange ‘ghosts’ around the drawing.

I did enable GL_POLYGON_SMOOTH, but here are is the ‘ghosting’ that I’m talking about:

http://www.hindbrain.net/ghosts.jpg

William

I created a minimal test program. Here is the result:

http://www.hindbrain.net/example.jpg

Is there a way to get less ragged edges on such a shape?
Here’s the essential code:

GLdouble shape[4][3] = {
{-3, 3.8, 0},
{ 0, 3.0, 0},
{ 3, 3.8, 0},
{ 0, 3.7, 0}
};

int InitGL(GLvoid) {
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
return TRUE;
}

GLuint compile(void) {
GLuint id = glGenLists(1);

if(!id) return id;

GLUtesselator *tess = gluNewTess();
if(!tess) return 0;

gluTessCallback(tess, GLU_TESS_BEGIN, (void (CALLBACK *)())tessBeginCB);
gluTessCallback(tess, GLU_TESS_END, (void (CALLBACK *)())tessEndCB);
gluTessCallback(tess, GLU_TESS_ERROR, (void (CALLBACK *)())tessErrorCB);
gluTessCallback(tess, GLU_TESS_VERTEX, (void (CALLBACK *)())tessVertexCB);

glNewList(id, GL_COMPILE);
glColor3ub(0, 255, 255);
gluTessBeginPolygon(tess, 0);
gluTessBeginContour(tess);
gluTessVertex(tess, shape[0], shape[0]);
gluTessVertex(tess, shape[1], shape[1]);
gluTessVertex(tess, shape[2], shape[2]);
gluTessVertex(tess, shape[3], shape[3]);
gluTessEndContour(tess);
gluTessEndPolygon(tess);
glEndList();

gluDeleteTess(tess);

return id;
}

int draw(GLvoid) {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glTranslatef(0.0f, -3.5f, -6.0f);

glEnable( GL_BLEND );
glEnable(GL_POLYGON_SMOOTH);
glCallList(listId1);
glDisable(GL_POLYGON_SMOOTH);
glDisable( GL_BLEND );

return TRUE;
}

William