如何在 QOpenGLTexture 中创建带 alpha 的纹理?

Posted

技术标签:

【中文标题】如何在 QOpenGLTexture 中创建带 alpha 的纹理?【英文标题】:How to create a texture with alpha in QOpenGLTexture? 【发布时间】:2016-10-22 01:01:57 【问题描述】:

我正在尝试使用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);

有什么建议吗?

【问题讨论】:

谢谢回复,我已经解决了,好像是gl功能设置的问题。 【参考方案1】:

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

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

现在它起作用了。

【讨论】:

以上是关于如何在 QOpenGLTexture 中创建带 alpha 的纹理?的主要内容,如果未能解决你的问题,请参考以下文章