PDA

View Full Version : Aliasing of filled (tessellated) edges



wwuster
12-18-2009, 09:54 AM
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

wwuster
12-18-2009, 11:00 AM
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

Frodak
12-18-2009, 11:29 AM
You need to enable anti-aliasing for the filled polygon.

ZbuffeR
12-18-2009, 11:52 AM
How do you smooth the "unfilled" rounded box ? With GL_LINE_SMOOTH ? Then for filled primitives, you should also enable GL_POLYGON_SMOOTH.

wwuster
12-18-2009, 12:00 PM
You need to enable anti-aliasing for the filled polygon.


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

wwuster
12-21-2009, 03:45 AM
I did enable GL_POLYGON_SMOOTH, but here are is the 'ghosting' that I'm talking about:

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

William

wwuster
12-23-2009, 06:38 AM
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