mpen
mpen

Reputation: 283345

GL_POLYGON not filled properly?

Why are those lines appearing in my shape?

I'm initializing OpenGL like this:

glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_COLOR_MATERIAL);
glEnable(GL_BLEND);
glEnable(GL_POLYGON_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0, 0, 0, 0);

And drawing the shape like this:

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1, 0, 0);
glBegin(GL_POLYGON);
    glVertex2f(-5, -5); // bottom left
    glVertex2f(5, -5); // bottom right...
    glVertex2f(6, 0);
    glVertex2f(5, 5);
    glVertex2f(-5, 5);
glEnd();

Doesn't matter if it's clockwise or CCW.

Upvotes: 1

Views: 4230

Answers (2)

David
David

Reputation: 2174

I think disabling GL_POLYGON_SMOOTH would fix that, but you'd lose the antialiasing. FSAA would work as an alternative, but it'd be slower.

Edit: looking around, there are a lot of examples out there using glBlendFunc( GL_SRC_ALPHA_SATURATE, GL_ONE );

Upvotes: 4

Goz
Goz

Reputation: 62333

GL_POLYGON_SMOOTH is an antiquated and slow method of polygon anti-aliasing. It also results in the problem you see above.

Using the Multisample buffer extension is the best way to perform fast anti-aliasing on modern machines. Read more here.

Upvotes: 3

Related Questions