I'm working on a GUI library for my game, and I'm having problems with my blending.
I have a 3D scene, which I render with glDrawArrays. In the fragment shader the alpha color is hardcoded 1.0f (gl_FragColor).
When I render a 2D quad on my screen with 1.0f in the alpha channel, my quad is semi-transparent, while it should be completely opaque.
I render the quad with the basic glBegin(GL_QUADS) and glColor4f(0.0f, 0.0f, 1.0f, 1.0f).
I enabled blending with the function:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
What am I doing wrong? Why is my quad semi-transparent?
Screenshot:
Fragment shader:
#version 130
varying vec2 texture_coordinate;
uniform sampler2D texture;
void main()
{
vec3 textureColor = texture2D(texture, texture_coordinate).rgb;
gl_FragColor = vec4(textureColor, 1.0f);
}
Quad render code:
glBegin(GL_QUADS);
glColor4f(0.0f, 0.0f, 0.7f, 1.0f);
glVertex2f(position.x, position.y + size.y);
glVertex2f(position.x + size.x, position.y + size.y);
glVertex2f(position.x + size.x, position.y);
glVertex2f(position.x, position.y);
glEnd();
Thanks in advance.
0.2 * vec3(0, 0, 1) + 0.8 * outsideColor
— that is, like an RGBA color of0, 0, 1, 0.2
. Assuming your screenshot has no color/gamma correction, anyway (which is likely since the colors line up neatly). I suggest looking around your code for where you have the number 0.2 or 0.8, to see where that might have arisen. \$\endgroup\$