Alpha blending and polygon antialiasing ?

Posted on 2006-10-19
Last Modified: 2013-12-06
 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,
Question by:Alexander
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 22

Expert Comment

ID: 17797073

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.  

Author Comment

ID: 17797449
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,
LVL 22

Expert Comment

ID: 17797531
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.
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!


Author Comment

ID: 17797656
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
It is a gold mine ! :D

Thank you anyway !

Author Comment

ID: 17809598
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,

This question is closed for me : considering that i've found the answer by myself, nobody gets any points.

Accepted Solution

Computer101 earned 0 total points
ID: 18320916
PAQed with points refunded (200)

EE Admin

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question