Anti-aliasing polygons on a white background

Hi,

I’ve nicely anti-aliased a sphere on a black background…


glEnable (GL_CULL_FACE);
glClear (GL_COLOR_BUFFER_BIT);
glEnable (GL_BLEND);
glEnable (GL_POLYGON_SMOOTH);
glDisable (GL_DEPTH_TEST);
glCullFace (GL_BACK);
glBlendFunc ( GL_SRC_ALPHA_SATURATE, GL_ONE );
glClearColor (0.0, 0.0, 0.0, 0.0);

…but I am really struggling to achieve the same effect on a white background. ( object becomes transparent when glClearColor is set to (1.0, 1.0, 1.0, 0.0 ) ).

I’ve played with various blending functions, but without success…

Any help would be much appreciated,

Many thanks

Alex.

Hi,
You can try to use
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
This one is recommended for lines, but on my graphic card it also works for quad strips. I’ll try it now on polygons. I also tried the blend function you mentioned, that is specified in the OpenGL Programming Guide and in MSDN, but found similar problems.
If your graphic card doesn’t have hardware support for the polygon antialiasing, the results might be very poor. I hope someone that had better results will reply…

I forgot to mention that I have tried that combination, and although it does anti-alias, the vertices become visible, and also the objects then become semi-opaque…

Many thanks,

Alex.

Originally posted by Tzupy:
Hi,
You can try to use
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
This one is recommended for lines, but on my graphic card it also works for quad strips. I’ll try it now on polygons. I also tried the blend function you mentioned, that is specified in the OpenGL Programming Guide and in MSDN, but found similar problems.
If your graphic card doesn’t have hardware support for the polygon antialiasing, the results might be very poor. I hope someone that had better results will reply…

Hi,
What do you mean by ‘vertices become visible’? From my experience what can happen is that triangle edges become a bit visible, except when drawing with black on white. There was a topic with this subject on the 4th of Sep., called ‘Antialiasing and cracks’. The interior of the polygon shouldn’t be affected by blending, so I don’t know why you get ‘semi-opaque’ results. What graphic card do you have? I have a GeForce2 Ti patched as a Quadro2 Pro. I tested antialiasing using the blend function I mentioned before on GeForce4 (works), on M-Radeon 7500 (works with more visible cracks) and on Radeon 9700 (doesn’t work, yet). The rendering context you request and get might be an issue. I’m trying to use full acceleration, but it might be not available on some cards / drivers…

Hi,

Yes, the triangle edges now become visible…

I did read the topic regarding anti-aliasing and cracks and it does seem to be the same issue ( and the issue did not seem to be resolved in that topic ).

I should elaborate a bit - the transparency is only apparent when two objects are ontop of each other ( they become blended together to some extent ). If I draw two identical overlayed objects it does pretty much eliminate the cracks, 3 objects completely - but its not a very elegant solution!

I have a 3DLabs Oxygen GVX1-Pro - i think the OpenGL handling is pretty solid.

cheers

Alex.

Originally posted by Tzupy:
Hi,
What do you mean by ‘vertices become visible’? From my experience what can happen is that triangle edges become a bit visible, except when drawing with black on white. There was a topic with this subject on the 4th of Sep., called ‘Antialiasing and cracks’. The interior of the polygon shouldn’t be affected by blending, so I don’t know why you get ‘semi-opaque’ results. What graphic card do you have? I have a GeForce2 Ti patched as a Quadro2 Pro. I tested antialiasing using the blend function I mentioned before on GeForce4 (works), on M-Radeon 7500 (works with more visible cracks) and on Radeon 9700 (doesn’t work, yet). The rendering context you request and get might be an issue. I’m trying to use full acceleration, but it might be not available on some cards / drivers…

Hi,
Yes, you have a decent professional card, so OpenGL should behave by the book. My card has only four bits of subpixel precision, and I suspect that could be the cause for the cracks. But an imprecise blending computation could be also a cause. I wonder if the blending could be replaced by a fragment program. What I find annoying is that in the previous antialiasing topic that guy said the (GL_SRC_ALPHA, GL_ONE) *** DID *** eliminate the cracks, but that works only on black background (I have to check progressively lighter gray backgrounds). And he was drawing on white background…

Everything works fine on a black background with ( GL_SRC_ALPHA_SATURATE, GL_ONE )…lovely solid anti-aliased objects - without cracks.

Using (GL_SRC_ALPHA, GL_ONE) i get the same effect, but objects become semi-transparent.

Both give invisible ( white )objects on a white background…

I am wondering if there is indeed a suitable blending function for this - although I find it hard to believe its not possible without cludging it.

hmmm…

Alex.

Originally posted by Tzupy:
Hi,
Yes, you have a decent professional card, so OpenGL should behave by the book. My card has only four bits of subpixel precision, and I suspect that could be the cause for the cracks. But an imprecise blending computation could be also a cause. I wonder if the blending could be replaced by a fragment program. What I find annoying is that in the previous antialiasing topic that guy said the (GL_SRC_ALPHA, GL_ONE) *** DID *** eliminate the cracks, but that works only on black background (I have to check progressively lighter gray backgrounds). And he was drawing on white background…

Hi,
Apparently it’s not possible to do the glBlendFunc( GL_SRC_ALPHA_SATURATE, GL_ONE ) with a background other than black… damn. A possible workaround would be to draw a black quad (with blending disabled), then draw your geometry with inverted colors, then invert the result (but I’m not sure yet how to do the inversion). For the cracks at the triangle edges, you may want to check your GL_SUBPIXEL_BITS value (it’s an estimate), maybe it’s also 4 like mine. Nvidia are touting their Quadro FX having 12 subpixel bits of precision and geting rid of these cracks. I still don’t understand why one blending setting generates cracks and another doesn’t, with the same displayed geometry…
May I suggest that you post this topic in the Advanced section, I’m afraid in this section I am the only one that answers.
It might be possible to build a custom blend function (that does the desired job) as a fragment program…

Hi again,
Would you mind if I would post this topic to the advanced section? I also want to ask how to build a custom blending function for antialiasing purposes.

Not at all - be great to find a solution…

cheers

Alex.

Originally posted by Tzupy:
Hi again,
Would you mind if I would post this topic to the advanced section? I also want to ask how to build a custom blending function for antialiasing purposes.

Hi Alex,
If you are still interested, here is how to draw AA polygons on white background:

  • set the background color to black, transparent;
  • draw your geometry with GL_SRC_ALPHA_SATURATE, GL_ONE blending setting; the top-most polygon first, opaque;
  • after finishing the geometry, draw a white opaque quad over the screen, keeping the same blending setting; it does clear the background to white; the stuff above worked even with black polygons (opaque) drawn on black transparent background.
    Bye,
    Tzupy