3
\$\begingroup\$

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: Why is my quad semi-transparent?

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.

\$\endgroup\$
13
  • 1
    \$\begingroup\$ Nothing is obviously wrong with what you've shown. I suggest providing more information: • A screenshot of the problem • Your fragment shader code \$\endgroup\$
    – Kevin Reid
    Commented Jul 7, 2013 at 22:50
  • \$\begingroup\$ Added your suggestions. \$\endgroup\$
    – Basaa
    Commented Jul 8, 2013 at 6:01
  • \$\begingroup\$ Firstly, did you mean glBegin(GL_QUADS) rather than glEnable(GL_QUADS) (which is invalid). Secondly, can you paste the code that draws the quad? \$\endgroup\$
    – elFarto
    Commented Jul 8, 2013 at 20:24
  • \$\begingroup\$ Yes I bean glBegin, sorry. Added the quad code. \$\endgroup\$
    – Basaa
    Commented Jul 8, 2013 at 20:56
  • \$\begingroup\$ FYI, I did a little calculation based on the color values in your screenshot, and the colors inside the rectangle vs. outside are pretty close to 0.2 * vec3(0, 0, 1) + 0.8 * outsideColor — that is, like an RGBA color of 0, 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\$
    – Kevin Reid
    Commented Jul 9, 2013 at 3:04

1 Answer 1

2
\$\begingroup\$

After a long debugging session with Basaa, we discovered that the problem was that texturing was still enabled. We just had to add:

glDisable(GL_TEXTURE_2D)
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .