I am loading a PNG using:
theImage = [NSBitmapImageRep imageRepWithContentsOfFile:imagePath];
from which I can successfully create a gl texture and render correctly without any transparency. However, when I switch blending on using:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
The texture renders with the correct transparent background, but the开发者_运维百科 image colours are incorrect.
I have tried several options in the blend function, GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
, GL_ONE
, GL_DST_ALPHA
, etc.
I was taught maybe I need to reorder the bits in the image data, maybe the channels have been mixed up, but I would not expect it to render correctly when blending is off in that case.
Alternatively, I could use libPNG I guess, but I would like to try using a NSBitmapImageRep
if it is possible.
How about supplying a screenshot?
Anyway, your blending function is wrong either way for simple transparency channel blending. It should be either
- normal alpha:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
or
- premultiplied alpha:
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
精彩评论