SugarAnnie 2019-10-17 15:31 采纳率: 0%
浏览 558

Qt 中自定义一个1D纹理QOpenGLTexture

我想在Qt的QOpenGLWidget上显示自定义的纹理,其中自定义了一个1D纹理,一个2D纹理,一个3D纹理,然后传给shader使用,下面是自定义1D纹理的代码:

void QImage3DView::initTexture1D() {
    const int MAX_CNT = 10000;
    GLubyte *tff = (GLubyte *)calloc(MAX_CNT, sizeof(GLubyte));

    for (int i = 0; i < 180; i++) {
        tff[i * 4 + 0] = GLubyte(100);
        tff[i * 4 + 1] = GLubyte(100);
        tff[i * 4 + 2] = GLubyte(100);
        tff[i * 4 + 3] = GLubyte(1);
    }

    for (int i = 180; i < 208; i++) {
        int a = (i - 179) * 2;
        if (a > 10) a = 6;

        tff[i * 4 + 0] = GLubyte(255);
        tff[i * 4 + 1] = GLubyte(255);
        tff[i * 4 + 2] = GLubyte(255);
        tff[i * 4 + 3] = GLubyte(4);
    }

    for (int i = 208; i < 255; i++) {
        tff[i * 4 + 0] = GLubyte(0);
        tff[i * 4 + 1] = GLubyte(0);
        tff[i * 4 + 2] = GLubyte(0);
        tff[i * 4 + 3] = GLubyte(0);
    }

    *(tff + 1020) = '\0';

    m_texture1D = new QOpenGLTexture(QOpenGLTexture::Target1D);
    m_texture1D->setSize(255);
    m_texture1D->allocateStorage(QOpenGLTexture::PixelFormat::RGBA, QOpenGLTexture::PixelType::UInt8);
    m_texture1D->setData(0, QOpenGLTexture::PixelFormat::RGBA, QOpenGLTexture::PixelType::UInt8, tff);//(VOID*)
    m_texture1D->setMinificationFilter(QOpenGLTexture::Nearest);
    m_texture1D->setMagnificationFilter(QOpenGLTexture::Linear);
    m_texture1D->setWrapMode(QOpenGLTexture::DirectionS, QOpenGLTexture::Repeat);

    free(tff);
}

但是在shader中用不了这个纹理,渲染出来的都是黑色的,2D纹理和3D纹理也同样用不了。但是如果2D纹理使用QImage读图片的方式是可以显示的,所以我怀疑自定义纹理的方式可能有问题,请帮忙看一下代码,搞了几天了。。。

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-20 17:55
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办