QOpenGLTexture (Qt)从原始数据(freeimage)

QOpenGLTexture (Qt) from raw data (freeimage)

本文关键字:freeimage 原始数据 QOpenGLTexture Qt      更新时间:2023-10-16

我一直在使用旧的Qt OpenGl方法,但现在是时候切换到较新的方法了。

位图一个FIBITMAP*正确初始化

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height,0,GL_BGRA GL_UNSIGNED_BYTE (void *) FreeImage_GetBits (pImage));

对我来说很有吸引力。

但是现在在较新的方法中,更倾向于使用QOpenGLTexture

不幸的是,我的尝试没有成功。

QOpenGLTexture*qtexture = newQOpenGLTexture (QOpenGLTexture:: Target2D);

纹理-> setData (QOpenGLTexture:: PixelFormat:: RGBA,QOpenGLTexture:: PixelType:: Int8 FreeImage_GetBits(位图));

代码返回1x1纹理但如果我使用

强制大小

qtexture setSize ->(宽度、高度,4);

qtexture有适当的大小,但它完全是黑色的,我也试图在Qt/Freeimage论坛等搜索,但没有相关的不幸的是,每个人都使用QImage来喂养QOpenGLTexture,但不幸的是,我需要支持一些"奇怪"的文件格式,如。hdr或。exr,不支持Qt本身。

提前感谢您的时间!

对于QOpenGLTexture,必须在allocateStorage之前设置SizeFormat。最后一步是setData

QOpenGLTexture *text = new QOpenGLTexture(QOpenGLTexture::Target2D);
text->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear);
text->create();
// given some `width`, `height` and `data_ptr`
text->setSize(width, height, 1);
text->setFormat(QOpenGLTexture::RGBA8_UNorm);
text->allocateStorage();
text->setData(QOpenGLTexture::Red, QOpenGLTexture::UInt8, data_ptr);

qtexture -> allocateStorage ();

是关键!