bobbyrne01
bobbyrne01

Reputation: 6745

alpha not changing transparency of object using glsl shader

How come when i manually change the alpha value in array, being passed to shader, the result is the same for both 0.0f and 1.0f?

I was expecting the object to be drawn with some level of transparency, depending on alpha value.

I'm not using any textures. I always see my red object against a black background.

accessing glsl variable from java ..

float[] color = {1.0f, 0.0f, 0.0f, 1.0f};

gl2.glGetUniformLocation(shaderProgram, "vColor");
gl2.glUniform4fv(mColorHandle, 1, color, 0);

glsl, fragment shader ..

#version 120

uniform vec4 vColor;

void main() {
    gl_FragColor = vColor;
    gl_FragColor.a = 0.0; // does not make object transparent
    // gl_FragColor.a = 1.0; // does not make object transparent
}

Upvotes: 21

Views: 11576

Answers (1)

bobbyrne01
bobbyrne01

Reputation: 6745

Needed to enable blending ..

gl2.glEnable(GL.GL_BLEND);
gl2.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

Upvotes: 32

Related Questions