如何在QOpenGLTexture中使用alpha创建纹理?

时间:2016-10-22 01:01:57

标签: c++ qt opengl-es-2.0 qtopengl

我正在尝试使用QImageQOpenGLTexture生成纹理。 我已将QImage颜色格式设置为RGBA8888,并使用setPixel设置颜色,但似乎无论我如何更改Alpha值,它仍保持为255,并且透明度图片永远不会改变。

这是我的代码:

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);

有什么建议吗?

1 个答案:

答案 0 :(得分:2)

我发现了问题,它不是来自纹理本身的设置。 这是因为我没有将gl函数设置为正确。 我添加了

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

现在它奏效了。