PDA

View Full Version : Polygon Antialiasing question



xunhuan
10-31-2003, 04:33 PM
Hello,

The following is my polygon antialiasing code:

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

glPushMatrix();
glBegin(GL_POLYGON)
glVertex3f(-1.0f ,0.0f, -1.0f);
glVertex3f(1.0f, 0.0f, -1.0f);
glVertex3f(1.0f, 0.0f, 1.0f);
glVertex3f(-1.0f, 0.0f, 1.0f);
glEnd()
glPopMatrix();

glDisable(GL_BLEND);
glDisable(GL_POLYGON_SMOOTH);

However, The diagonal line of the polygon is partly the background color. Can anyone tell me what's the problem here?

It seems like OpenGL cut the polygon into triangles and anti-alias each triangle instead of the whole polygon.

Leyder Dylan
10-31-2003, 05:18 PM
Hi,

I use this, and it works :
// Blending params
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

// Anti-Aliasing params
glEnable(GL_LINE_SMOOTH);

// AA ==> ON
glEnable(GL_LINE_SMOOTH);

glLineWidth(55.0f);
glBegin(GL_LINES);
glVertex3f(-18.0f,-6.0f, 0.0f);
glVertex3f(8.0f,6.0f,0.0f);
glEnd();

Yes it's for the lines but should work with polygons

Tzupy
11-01-2003, 05:33 AM
Hi,
There was a topic on this matter about a month ago, and the conclusion is here:
- to antialias polygons you have to draw on black transparent background (even when drawing with black);
- use the blending function GL_SRC_ALPHA_SATURATE, GL_ONE (of course, first enable blending and polygon smoothing);
- draw your geometry from front (first) to back (last), with depth buffering disabled;
- to get the desired background colour, draw one last quad over the result;
This might not work properly on cards that are not professional ones. It still seems to work on GeForce4s, but not on Radeons. Basically, you need to have a card / driver that makes use of the computed coverage. Anyway, you should request (and hopefully get) an accelerated rendering context, the generic implementation eihter is dead slow or doesnt' work at all.
The lines between the triangles (when using the line smoothing blending function) are there because the triangles are blended one at a time, and the blending on the inner edges is done not with the background, but with the already blended edge.
Hope I was clear enough.