0
\$\begingroup\$

I wanted to add transparency for my UI elements, so I enabled blending by adding:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

before renderer and

glDisable(GL_BLEND);

after renderer.

So I tried to render simple rectangle (with glDrawArrays() because I'm using GLSL shaders).

Before I enabled blending my rectangle (1 quad) looked like this:

BEFORE

And now, after blending it looks like this (Like a two triangles):

AFTER

Do I need some extra settings for my blending or what?

Edit:

I noticed that if I remove anti-aliasing code:

glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glEnable(GL_LINE_SMOOTH);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_POLYGON_SMOOTH);

Problem will disappear, but I want to keep anti-aliasing in my game. Any ideas?

\$\endgroup\$
1
\$\begingroup\$

Modern hardware often lacks the ability to actually draw quads. If you're using a legacy API like OpenGL, the drivers will generally just emulate quad support by asking the hardware to draw two triangles.

With general edge smoothing, you'd get pretty much exactly what you're seeing. Of course, polygon smoothing itself is a legacy artifact of OpenGL's history and not a feature you should actually be using in modern code.

If you want anti-aliasing, use MSAA or a post processing filter to smooth your scene. Do not use the OpenGL smoothing controls. They're effectively dead legacy cruft in the GL API. I'm surprised they work at all still, honestly.

Notes on how polygon smoothing produces the effects you're seeing.

Apple apparently removed support for polygon smoothing entirely almost a decade ago.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.