查看完整版本: [-- 有谁用过 QOpenGLTexture 做skybox吗? --]

QTCN开发网 -> Qt基础编程 -> 有谁用过 QOpenGLTexture 做skybox吗? [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

o2co2 2014-05-08 00:13

有谁用过 QOpenGLTexture 做skybox吗?

我一直不成功不知为什么?

请大家帮帮忙

skyTex = new QOpenGLTexture( QOpenGLTexture::TargetCubeMap );    skyTex->create();    skyTex->bind( 0 );    skyTex->setSize(512,512);    skyTex->allocateStorage();//    skyTex->setMipLevels(0);//    skyTex->setLayers(1);
    QString fileName;    fileName = "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/snow_posx.jpg";    QImage image_posx( fileName );
    skyTex->setData( 0,0,QOpenGLTexture::CubeMapPositiveX,QOpenGLTexture::RGBA,QOpenGLTexture::UInt8,image_posx.bits() );
    fileName = "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/snow_negx.jpg";    QImage image_negx( fileName );    skyTex->setData( 0,0,QOpenGLTexture::CubeMapNegativeX,QOpenGLTexture::RGBA,QOpenGLTexture::UInt8,image_negx.bits() );
    fileName = "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/snow_posy.jpg";    QImage image_posy( fileName );    skyTex->setData( 0,0,QOpenGLTexture::CubeMapPositiveY,QOpenGLTexture::RGBA,QOpenGLTexture::UInt8,image_posy.bits() );
    fileName = "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/snow_negy.jpg";    QImage image_negy( fileName );    skyTex->setData( 0,0,QOpenGLTexture::CubeMapNegativeY,QOpenGLTexture::RGBA,QOpenGLTexture::UInt8,image_negy.bits() );
    fileName = "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/snow_posz.jpg";    QImage image_posz( fileName );    skyTex->setData( 0,0,QOpenGLTexture::CubeMapPositiveZ,QOpenGLTexture::RGBA,QOpenGLTexture::UInt8,image_posz.bits() );
    fileName = "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/snow_negz.jpg";    QImage image_negz( fileName );    skyTex->setData( 0,0,QOpenGLTexture::CubeMapNegativeZ,QOpenGLTexture::RGBA,QOpenGLTexture::UInt8,image_negz.bits() );//    skyTex->create();
    skyTex->setWrapMode(QOpenGLTexture::DirectionS, QOpenGLTexture::ClampToEdge  );    skyTex->setWrapMode(QOpenGLTexture::DirectionR, QOpenGLTexture::ClampToEdge  );    skyTex->setWrapMode(QOpenGLTexture::DirectionT, QOpenGLTexture::ClampToEdge  );    skyTex->setMinificationFilter( QOpenGLTexture::Linear );    skyTex->setMagnificationFilter(  QOpenGLTexture::Linear );    qDebug()<<"textureId:"<<skyTex->textureId();

自强不吸 2014-05-08 17:18
视口要位于盒子里面,(顺便描述下你遇到的问题)

o2co2 2014-05-09 00:55
你试过QOpenGLTexture这个类吗?
问题应用上面的skybox是全黑的

o2co2 2014-05-10 11:16
这样也尝试了
skyTex = new QOpenGLTexture( QOpenGLTexture::TargetCubeMap );
    skyTex->create();
    skyTex->bind();
    skyTex->setSize(512,512);
    skyTex->allocateStorage();
    QString fileName;
    fileName = "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/snow_posx.jpg";
    QImage image_posx( fileName );
    skyTex->setData( 1,1,QOpenGLTexture::CubeMapPositiveX,QOpenGLTexture::RGBA,QOpenGLTexture::UInt8,image_posx.bits() );
    fileName = "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/snow_posx.jpg";
    QImage image_negx( fileName );
    skyTex->setData( 1,1,QOpenGLTexture::CubeMapNegativeX,QOpenGLTexture::RGBA,QOpenGLTexture::UInt8,image_negx.bits() );
    fileName = "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/snow_posx.jpg";
    QImage image_posy( fileName );
    skyTex->setData( 1,1,QOpenGLTexture::CubeMapPositiveY,QOpenGLTexture::RGBA,QOpenGLTexture::UInt8,image_posy.bits() );
    fileName = "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/snow_posx.jpg";
    QImage image_negy( fileName );
    skyTex->setData( 1,1,QOpenGLTexture::CubeMapNegativeY,QOpenGLTexture::RGBA,QOpenGLTexture::UInt8,image_negy.bits() );
    fileName = "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/snow_posx.jpg";
    QImage image_posz( fileName );
    skyTex->setData( 1,1,QOpenGLTexture::CubeMapPositiveZ,QOpenGLTexture::RGBA,QOpenGLTexture::UInt8,image_posz.bits() );
    fileName = "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/snow_posx.jpg";
    QImage image_negz( fileName );
    skyTex->setData( 1,1,QOpenGLTexture::CubeMapNegativeZ,QOpenGLTexture::RGBA,QOpenGLTexture::UInt8,image_negz.bits() );

    skyTex->setWrapMode(QOpenGLTexture::DirectionS, QOpenGLTexture::ClampToEdge  );
    skyTex->setWrapMode(QOpenGLTexture::DirectionT, QOpenGLTexture::ClampToEdge  );
    skyTex->setMinificationFilter( QOpenGLTexture::Linear );
    skyTex->setMagnificationFilter(  QOpenGLTexture::Linear );

o2co2 2014-05-10 11:35
使用纯opengl是没有问题,如下面代码可以正常显示
glActiveTexture( GL_TEXTURE0 );
    GLuint texID;
    glGenTextures(1,&texID);
    glBindTexture( GL_TEXTURE_CUBE_MAP,texID );
    const char * suffixes[] = { "posx", "negx", "posy","negy", "posz", "negz" };
    GLuint targets[] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X,
                         GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
                         GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
                         GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
                         GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
                         GL_TEXTURE_CUBE_MAP_NEGATIVE_Z};
    for( int i = 0; i < 6; i++ ) {
        QString fileName = QString( "/Users/army/code/QT_OpenGL/OpenGLQT_Demos/assets/skybox/" ) + "snow_" + suffixes + ".jpg";
        QImage image( fileName );
        glTexImage2D(targets, 0, GL_RGBA,image.width(), image.height(),0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits());
    }
    // 典型的立方体映射设置
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE);
    //把 uniform 变量 CubeMapTex 设置到纹理单元 0
    GLuint uniloc = glGetUniformLocation(shader_box->programId(), "cubeMapTex");
    if( uniloc >= 0 )
        glUniform1i(uniloc, 0);
    // Use the seamless cubemap extensions
    if (  QOpenGLContext::currentContext()->hasExtension( "GL_ARB_seamless_cube_map" ) )
        glEnable( GL_TEXTURE_CUBE_MAP_SEAMLESS );
    else
        glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS);

tony2278 2017-06-19 11:45
你好!请问问题是怎样解决的呢?


查看完整版本: [-- 有谁用过 QOpenGLTexture 做skybox吗? --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled