0

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.

Jesse Beder
  • 33,081
  • 21
  • 109
  • 146
Seamus
  • 1,107
  • 10
  • 22

1 Answers1

4

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)
datenwolf
  • 159,371
  • 13
  • 185
  • 298