Link to home
Start Free TrialLog in
Avatar of Alexander
AlexanderFlag for France

asked on

Alpha blending and polygon antialiasing ?

Hi,
 I'm trying to display polygons with antialiasing over a not-black background. At first, i've used
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
And then everything goes well over a black background... But when i've anything with another color in background, it modifies the color of my polygon.
Then i've tried to use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); but then, i see the tesselated edges of my polygon.

So i'm looking for a way to get polygon edges antialiasing without having those nasty tesselated lines displayed... but keeping my original polygon's color, is it possible ? if yes, how ?

If you want, i can send you images by e-mail...

Thank you in advance,
Alexander
Avatar of NovaDenizen
NovaDenizen

http://glprogramming.com/red/chapter06.html

From the section "Antialiasing Polygons":
"In theory, you can antialias polygons in either RGBA or color-index mode. However, object intersections affect polygon antialiasing more than they affect point or line antialiasing, so rendering order and blending accuracy become more critical. In fact, they're so critical that if you're antialiasing more than one polygon, you need to order the polygons from front to back and then use glBlendFunc() with GL_SRC_ALPHA_SATURATE for the source factor and GL_ONE for the destination factor. Thus, antialiasing polygons in color-index mode normally isn't practical."

To do proper antialiased polygons, you have to use GL_SRC_ALPHA_SATURATE,GL_ONE and draw your polygons in front-to-back order.  You can't really use the z-buffer here, and you have to clear the alpha channel to zero before you start drawing, and draw your background in last of all.  
Avatar of Alexander

ASKER

Sorry i've the OpenGL programming guide (fifth edition) too, and i've already read that. The problem is that i'm rendering a 2D scene and then to manage objects superposition i need to draw them from background to top.

On another hand, since i've asked this question, i've learned that using GL_MULTISAMPLING could be the solution. I'm not using glut but windows SDK so i'm looking for now on how to get a multisampled OpenGL context. Maybe in PIXELFORMATDESCRIPTOR ?

Thankyou anyway,
Alexander
I'm not 100% sure on the low-level details, but I think you can only get polygon antialiasing that looks right if you follow the front-to-back requirement and use the (GL_SRC_ALPHA_SATURATE, GL_ONE) blend mode.  It intuitively seems like other ways of doing it would work, but unfortunately things like the triangle seams show up for polygons more complex than triangles.

I haven't used GL_MULTISAMPLING yet, so I can't really comment on it.
i think i've found how to activate multisampling on windows SDK, i'll try it and thell you if it work, take a look at http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=46
It is a gold mine ! :D

Thank you anyway !
Alexander
Ok, it wasn't easy but once it is done and activated there is no more tesselation anti-aliasing alpha-blending problems when using FAAS and multisampling ! now my scene looks pretty well !

Thank you anyway for trying,
Alexander

This question is closed for me : considering that i've found the answer by myself, nobody gets any points.
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial