首页 文章

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

提问于
浏览
3

我一直在使用旧的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,但不幸的是我需要支持一些“奇怪的”文件格式,如.hdr或 . 不受Qt本身支持的exr .

提前谢谢您的时间!

2 回答

  • 0

    qtexture-> allocateStorage();

    是关键!

  • 0

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

相关问题