Can't get GL_POLYGON_SMOOTH to work

I know it should be simple, but antialiasing using GL_POLYGON_SMOOTH doesn’t work for me.
I render the scene offscreen and then write the data to a tga file (see code). All settings are as they should be (I think). So what am I doing wrong? Any help will be appreciated.

Here are the relevant bits from my code:

glDrawBuffer(GL_BACK);

// transformations
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(627, -2.5, 260, 627, -2.5, 160, 1, 0, 0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(31, (float) width / (float) height, 0.005, 2000);

// settings
glShadeModel(GL_SMOOTH);
glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glEnable(GL_BLEND);
glEnable(GL_POLYGON_SMOOTH);
glDisable(GL_DEPTH_TEST);

glClearColor(0.0, 0.0, 0.0, 0.0);

// draw scene
glClear(GL_COLOR_BUFFER_BIT);

glColor4f(1, 1, 0, 1);
glBegin(GL_POLYGON);
glVertex3f(590, 20, 2);
glVertex3f(620, -33, 2);
glVertex3f(660, 0, 2);
glEnd();

glColor4f(1, 0, 0, 1);
glBegin(GL_POLYGON);
glVertex3f(580, -80, 0);
glVertex3f(670, 33, 0);
glVertex3f(630, -70, 0);
glEnd();

[…]
/* Here I check some OpenGL variables: GL_RED_BITS, GL_GREEN_BITS,
GL_BLUE_BITS and GL_ALPHA_BITS are 8 each, GL_RGBA_MODE, GL_BLEND
and GL_POLYGON_SMOOTH are true, GL_DEPTH_TEST is false.
The OpenGL version string is “1.2 Mesa 3.2” */

glFlush();

glBuffer->makeCurrent();
glFinish();

// read binary data
binData = new unsigned char[widthheight3];
glReadBuffer(GL_BACK);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, binData);

// make tga header
imgData = new unsigned char[widthheight3 + 18];
imgData[0] = 0;
imgData[1] = 0;
imgData[2] = 2;
imgData[12] = width%256;
imgData[13] = width>>8;
imgData[14] = height%256;
imgData[15] = height>>8;
imgData[16] = 24;
imgData[17] = 32;

// write tga data
for (int i=0; i<widthheight; i++) {
imgData[18+i
3] = binData[i*3+2];
imgData[18+i3+1] = binData[i*3+1];
imgData[18+i
3+2] = binData[i*3];
}
delete binData;
[…]

[This message has been edited by Shagrath (edited 01-09-2001).]

Most cards will simply ignore GL_POLYGON_SMOOTH. GeForce cards will use it but the result is a slooooooooooooww display !

As a genereal rule, using GL_POLYGON_SMOOTH on a non-professional card is not a good idea…

What card are you using?

Regards.

Eric

I’m using software rendering, so I don’t think it’s the card. (Speed is not important to me since I don’t need real-time rendering). I have the following packages installed: mesa-3.2-63, mesasoft-3.2-63 and mesadev-3.2-63 (Linux).

Oops sorry !

I do not know if Mesa uses the GL_POLYGON_SMOOTH hint or not…

You see, as a hint, it can be ignored and that’s what most OpenGL implementation do…

Regards.

Eric

Redbook on Polygon Antialiasing:
“Now you need to blend overlapping edges appropriately. First, turn off the depth buffer so that you have control over how overlapping pixels are drawn. Then set the blending factors to GL_SRC_ALPHA_SATURATE (source) and GL_ONE (destination). With this specialized blending function, the final color is the sum of the destination color and the scaled source color; the scale factor is the smaller of either the incoming source alpha value or one minus the destination alpha value. This means that for a pixel with a large alpha value, successive incoming pixels have little effect on the final color because one minus the destination alpha is almost zero. With this method, a pixel on the edge of a polygon might be blended eventually with the colors from another polygon that’s drawn later. Finally, you need to sort all the polygons in your scene so that they’re ordered from front to back before drawing them.”

Do you have destination alpha values on your screen?

Well, in the example code above, I first draw a yellow triangle with alpha value 1 and then an overlapping red triangle (also with an alpha value of 1). There’s no antialiasing whatsoever. I’ve tried alpha values other than 1, but that didn’t help.

It’s working now. In case someone else experiences the same problem, the cause of the problem seems to have been the software rendering (Mesa). I’m now using hardware accelerated rendering with the exact same code and the resulting image is antialiased.