0

I've been trying to find some concrete maths behind the innerworkings of glBlendFunc.

Just to clarify, I know that the blending equation is:

srcChannels * srcFactor + dstChannels * dstFactor = channelsRendered.

my question is, are srcChannels, dstChannels and channelsRendered the 3-vector (r,g,b) or the 4-vector (r,g,b,a)?

since (0.2, 0.2, 0.2, 1.0) and (1.0, 1.0, 1.0, 0.2) should look the same, there may be room for ambiguity here.

Matt Peck
  • 31
  • 1

1 Answers1

1

glBlendFunc works on all four channels; glBlendFuncSeparate separates RGB from alpha.

The glBlendFunc reference page describes all the different blend modes and the operations applied to the different channels. glBlendFuncSeparate does the same including operations on the alpha channel.

19greg96
  • 2,592
  • 5
  • 41
  • 55
radical7
  • 8,957
  • 3
  • 24
  • 33
  • Also, what does openGL interpret a completely transparent pixel as from a png file? (0,0,0,0) or (1,1,1,0)? – Matt Peck Mar 31 '13 at 17:57
  • I found out that openGL interprets a completely transparent pixel as (1,1,1,0), why is this? is there a way to make it interpret them as (0,0,0,0)? – Matt Peck Mar 31 '13 at 18:04
  • @MattPeck: "*what does openGL interpret a completely transparent pixel as from a png file?*" Neither; OpenGL does not *interpret* a PNG file. You *give* OpenGL arbitrary pixel data; OpenGL doesn't know or care that it came from a PNG file. It's the PNG decompressor that decides what a "transparent" pixel looks like, not OpenGL. – Nicol Bolas Mar 31 '13 at 23:08
  • @MattPeck Your question doesn't exactly make sense. A transparent pixel is transparent by virtue of having a zero alpha component. So, if that pixel is the source color, and you're using `GL_SRC_ALPHA` the fragment's color is irrelevant. However, I don't think that's what you're really getting at. If the problem is that a PNG file uses white when you want black, you could either remap this in a shader, or use `glPixelMap` if you're going prehistoric (and if you are, please use a shader). The reason this works is that fragment shaders are executed before the fragments are blended. – radical7 Apr 01 '13 at 15:59