Tuesday, March 1, 2011

Why do my semi-opaque vertices make background objects brighter in OpenGL?

I am rendering 4 vertices (a square) in front of a colored cube. The vertices are colored white, but are blended at 0.5f.

Related: Why does my colored cube not work with GL_BLEND?

Please could someone tell me why the colored cube appears brighter when obscured by the semi-opaque square?

Cube rendered without square in front:

Normal cube

And, rendered with the square:

Cube with square

Please see the code used to create the colored cube, the code used to actually draw the cube, and the code where the cube and square are rendered.

This is the code in my init function:

glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
From stackoverflow
  • I'd say it's because your semi-transparent square gets added to the existing pixels, thus incrementing their intensity.

    The documentation for glBlendFunc() recommends setting the second parameter to GL_ONE_MINUS_SRC_ALPHA, that is the boilerplate for implementing transparency. Try it.

    Karl : Yeah, looks like a white translucent square, I don't see the problem.
    nbolton : Excellent, thanks! GL_ONE_MINUS_SRC_ALPHA fixed the problem.

0 comments:

Post a Comment