ColorPicker4 and alpha blending

We are experience some differences between the imgui and a port in Kotlin regarding the alpha value in the ColorPicker4 selection color square.

Essentially, after swapping the buffers, in imgui I read an alpha value of 255 (1f) while on the jvm I got something variable from 255 at the top and at the bottom of the square, till 191 in the middle (vertical-wise).

|tablet%20(20190405115332)

ColorPicker4 draws two squares [here]:

draw_list->AddRectFilledMultiColor(picker_pos, picker_pos + ImVec2(sv_picker_size,sv_picker_size), IM_COL32_WHITE, hue_color32, hue_color32, IM_COL32_WHITE);

draw_list->AddRectFilledMultiColor(picker_pos, picker_pos + ImVec2(sv_picker_size,sv_picker_size), IM_COL32_BLACK_TRANS, IM_COL32_BLACK_TRANS, IM_COL32_BLACK, IM_COL32_BLACK);

The first one is opaque, while the second has the upper corners transparents.

To be precise, I actually have two issues here:

  • why on the jvm isn’t going from 255 bottom to 0 top, but this is on my side
  • why in imgui I see everywehere 255

Referring to the glfw sample, the blending status is set as [follow]:

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

This means, theoretically, that in ColorPicker4 after drawing the first opaque square on the default framebuffer, I shall have all 255.
Now, let’s choose the center of the second transparent square, where src alpha should be 0.5f.

Given sA as source alpha and dA as destination alpha, then the above blending means that the result alpha should be (reference):

sA * sA + dA * (1 - sA)

Given sA 0.5f and dA 1f, this means

0.5f * 0.5f + 1f * (1 - 0.5f) =
0.25f + 0.5f =
0.75f

So, why does imgui alpha end up in being 1f?

Since I cant post more than two links in the same post, here are the imgui references: