[SOLVED] OpenGL Blending on Linux

Hi and welcome to part 3 of my series: I can’t get OpenGL up and running on Linux.

As we’ve seen in part two, MSAA isn’t supported on Linux. So now I’m trying to fake anti aliasing with several transparent layers. I’m trying to set up transparency / blending as follows:

OpenGLComponent::OpenGLComponent() {
	setOpaque(true);
	m_openGL.setRenderer(this);
	m_openGL.setContinuousRepainting(true);
	m_openGL.attachTo(*this);
	
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);
}

I then pass colors via a uniform into my fragment shader. When rendering blue stuff with different alpha values on black / white, this is the result:

RGBA1
Fully opaque: so far, so good…

RGBA05
Half transparent: The blue section overlying the black background should not be fully blue.

RGBA0
Full transparent: There should be no blue in this image whatsoever.

I have noticed that changind the two lines

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

to different values, or even removing them completely makes no difference, so my guess is that some default blending mechanism is being used. Or perhaps the blending feature is missing as well on linux? (I don’t have access to a windows machine ATM to compare).

this should be called in the render function.

I think JUCE expects all rendering to use premultiplied colours. That means, for your semi-transparent blue, the RGBA values should be (0, 0, 0.5, 0.5), and for full transparency all pixel values should be 0.

This is the solution! Thanks!

After using the hint above, it seems the non-pre-multiplied values are consistent with what I get by using juce::Graphics draw calls. When pre-multiplying, values turn out too dim.