compare it with the original image without transparency:
the difference is vec4(fragColor, 0.5)
and vec4(fragColor, 1.0)
in the fragment shader:
program.addShaderFromSourceCode(QOpenGLShader::Fragment,
"#version 330\r\n"
"in vec3 fragColor;\n"
"out vec4 color;\n"
"void main() {\n"
" color = vec4(fragColor, 1.0);\n"
"}\n"
);
Is there some other option I can set?
My environment: Windows 10, MSVC 2019, QT 6.2.
EDIT1:
Did some further experimentation and added the following before rendering the triangle:
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
and got white background:
with glClearColor(0, 0, 0, 0.5)
I got gray:
CodePudding user response:
Your image viewer displays your image on a white background so you see white or gray. With glClearColor(0, 0, 0, 1)
you will see a transparent triangle on a black background:
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
but resulting triangle will be partially transparent, so white image viewer background will be partially visible under the triangle.