Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt 3D: How to draw a cube with 6 different textures on each face ?



  • Hi,
    I'm new to Qt 3D (C++), and while I'm training with my first 3D app, I couldn't achieve the following:
    Creating a cube with 6 different textures on each face... Until now, this is what I've tried:

        Qt3DExtras::QTextureMaterial *textureMaterial = new Qt3DExtras::QTextureMaterial();
        Qt3DRender::QTextureCubeMap *cubMap = new Qt3DRender::QTextureCubeMap();
    
        Qt3DRender::QTextureImage *f1 = new Qt3DRender::QTextureImage();
        Qt3DRender::QTextureImage *f2 = new Qt3DRender::QTextureImage();
        Qt3DRender::QTextureImage *f3 = new Qt3DRender::QTextureImage();
        Qt3DRender::QTextureImage *f4 = new Qt3DRender::QTextureImage();
        Qt3DRender::QTextureImage *f5 = new Qt3DRender::QTextureImage();
        Qt3DRender::QTextureImage *f6 = new Qt3DRender::QTextureImage();
    
        f1->setSource(QUrl("qrc:/rc/images/1.png"));
        f1->setFace(Qt3DRender::QAbstractTexture::CubeMapNegativeX);
        f2->setSource(QUrl("qrc:/rc/images/2.png"));
        f2->setFace(Qt3DRender::QAbstractTexture::CubeMapPositiveX);
        f3->setSource(QUrl("qrc:/rc/images/3.png"));
        f3->setFace(Qt3DRender::QAbstractTexture::CubeMapNegativeY);
        f4->setSource(QUrl("qrc:/rc/images/4.png"));
        f4->setFace(Qt3DRender::QAbstractTexture::CubeMapPositiveY);
        f5->setSource(QUrl("qrc:/rc/images/5.png"));
        f5->setFace(Qt3DRender::QAbstractTexture::CubeMapNegativeZ);
        f6->setSource(QUrl("qrc:/rc/images/6.png"));
        f6->setFace(Qt3DRender::QAbstractTexture::CubeMapPositiveZ);
    
        cubMap->addTextureImage(f1);
        cubMap->addTextureImage(f2);
        cubMap->addTextureImage(f3);
        cubMap->addTextureImage(f4);
        cubMap->addTextureImage(f5);
        cubMap->addTextureImage(f6);
    
        textureMaterial->setTexture(cubMap);
    

    But it gives me a black cube.
    I've googled for some examples, but all I find is OpenGl, which I'm not familiar with. I believe it's possible using Qt C++ Classes only...

    I would appreciate your help.


Log in to reply