0

I'm using FLTK 1.3 as base for OpenGL window context creation (Fl_Gl_Window), etc. on Mac OS X 10.9.

The goal is to create some grid with simple primitives on it. I've done some easy stuff with OpenGL in 2D before, but now i'm lost. All rendered as good, as it need to, except edges. They are all so, uhmmm... Edgy, you know.

edgy object on smooth lined grid

It's obvious that this objects need some anti-aliasing in any form. Will it be simple vendor-implementation-specific smooth AA or full Multisampling. Problem is i can't turn it on in FLTK. Can't for triangles, but can for lines.

So far, i tried glEnable(GL_POLYGON_SMOOTH), multisampling on window (seems not working), different blending funcs, changing shader models.

Maybe it is because of triangle fan structure of objects? Please help me and thanks to you!

Code used for object:

float object_width = 100;
float object_height = 50;
float object_x = 250;
float object_y = 100;

glColor3f(0, 0, 1);
glBegin(GL_TRIANGLE_FAN);
for(int i = 0; i < 30; i++)
   glVertex2f(object_x + (object_width / 2) * cosf(i * 12 * DEG2RAD), object_y + (object_height / 2) * sinf(i * 12 * DEG2RAD));
glEnd();

Code on window creation (just mode setting):

mode(FL_RGB | FL_ALPHA | FL_DOUBLE);

Code used on init:

glClearColor(0.9, 0.9, 0.9, 1);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Colored output, but not smooth
//glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE_MINUS_SRC_ALPHA); // All drawn black, no smooth
//glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE); // All drawn black, no smooth either

glEnable(GL_BLEND);

glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);

glEnable(GL_LINE_SMOOTH);
glEnable(GL_POLYGON_SMOOTH); // not working???

On different blending modes than GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA getting this picture:

black non-smooth ellipse

TSB99X
  • 3,260
  • 2
  • 18
  • 20
  • 1
    For `GL_POLYGON_SMOOTH` to work correctly, you need two things: **1.** a pixel format that stores destination alpha and **2.** `GL_SRC_ALPHA_SATURATE` for your blending src. factor. Point 2 clearly is not observed here, and point 1 is impossible to validate given the fact that you have not listed your context setup code. – Andon M. Coleman Jun 08 '14 at 20:20
  • @AndonM.Coleman added mode init line to question and example of GL_SRC_ALPHA_SATURATE src blending. – TSB99X Jun 08 '14 at 21:31
  • 1
    I was not familiar with FLTK, so I took a look at the API docs. The changes you made are correct, you need `| FL_ALPHA` to allocate destination alpha. But the blend function should be `GL_SRC_ALPHA_SATURATE, GL_ONE` (which is creating a black blob for you and this behavior is actually typical of a framebuffer without destination alpha, which is strange). FLTK does let you allocate a multi-smapled framebuffer, using `| FL_MULTISAMPLE`, but the only thing strange is it does not let you specify the number of samples as best I can tell, making it kind of worthless :-\ – Andon M. Coleman Jun 08 '14 at 21:48
  • @AndonM.Coleman thanks to you for try. It seems that it is really hardware-dependent features (smoothing AA) and not supported on newer graphical cards, here old topic from 2008: [www.opengl.org](https://www.opengl.org/discussion_boards/showthread.php/165321-Problem-with-glBlendFunc!!) – TSB99X Jun 09 '14 at 02:56

0 Answers0