2

I'm trying to generate a texture with QImage and QOpenGLTexture. I've set the QImage color format to RGBA8888, and set color with setPixel, but it seems like no matter how I change the alpha value, it remains to 255, and the transparency of the picture will never change.

Here's my code:

QImage texPic(width, height, QImage::Format_RGBA8888);
texPic.setPixel(0, 0, qRgba(255,0,0,0));
texPic.setPixel(0, 1, qRgba(0,255,0,100));
QOpenGLTexture *texture = new QOpenGLTexture(texPic);

Any suggestions?

frogatto
  • 28,539
  • 11
  • 83
  • 129
mtyong
  • 121
  • 1
  • 3
  • 13
  • Thank you for the reply, and I've solve the problem, it seems like it's the gl functions setting problem. – mtyong Oct 24 '16 at 16:43

1 Answers1

2

I've found the problem, it's not from the setting of texture itself. It because I didn't get the gl functions setting right. I added

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

And now it worked.

mtyong
  • 121
  • 1
  • 3
  • 13