【问题标题】:QOpenGLTexture (Qt) from raw data (freeimage)来自原始数据的 QOpenGLTexture (Qt) (freeimage)
【发布时间】:2015-09-19 09:57:03
【问题描述】:

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

作为位图正确初始化的 FIBITMAP*

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 宽度, 高度,0, GL_BGRA,GL_UNSIGNED_BYTE, (void*)FreeImage_GetBits(pImage));

对我来说就像一个魅力。

但现在在较新的方法中,最好使用 QOpenGLTexture

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

QOpenGLTexture*qtexture = 新 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。

提前感谢您的宝贵时间!

【问题讨论】:

    标签: c++ qt opengl freeimage


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      qtexture->allocateStorage();

      是关键!

      【讨论】:

      • 使用QOpenGLTexture对象代替纯OpenGL有什么好处?
      • 这是 Qt 包装器,更易于与 Qt OpenGL 小部件一起使用
      猜你喜欢
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多