gpt4 book ai didi

c++ - 来自原始数据的 QOpenGLTexture (Qt) (freeimage)

转载 作者:太空狗 更新时间:2023-10-29 23:14:42 26 4
gpt4 key购买 nike

我一直在使用旧的 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 = new QOpenGLTexture(QOpenGLTexture::Target2D);

texture->setData(QOpenGLTexture::PixelFormat::RGBA, QOpenGLTexture::PixelType::Int8,FreeImage_GetBits(bitmap));

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

一样强制大小

qtexture->setSize(width,height,4);

qtexture 有合适的大小,但它是全黑的,我也尝试在 Qt/Freeimage 论坛等中搜索,但不幸的是没有任何相关的东西,不幸的是每个人都使用 QImage 来提供 QOpenGLTexture 但不幸的是我需要支持一些“奇怪的”文件格式,比如 . Qt 本身不支持的 hdr 或 .exr。

提前感谢您的宝贵时间!

最佳答案

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

关于c++ - 来自原始数据的 QOpenGLTexture (Qt) (freeimage),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32666824/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com