Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use QMetalRoughMaterial with QExtrudedTextMesh

How to use QMetalRoughMaterial with QExtrudedTextMesh

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 413 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • DiracsbracketD Offline
    DiracsbracketD Offline
    Diracsbracket
    wrote on last edited by
    #1

    Hi,
    I want to apply a metalic material to a 3D text.

    I have based my example code on this:
    https://code.woboq.org/qt5/qt3d/examples/qt3d/3d-text/main.cpp.html

    The example uses the QPhongMaterial. I naively thought I could simply
    replace that material by QMetalRoughMaterial , but that does not seem
    to work.

    My code is as follows:

    #include <QCoreApplication>
    #include <Qt3DCore/Qt3DCore>
    #include <Qt3DExtras/Qt3DExtras>
    #include <Qt3DExtras/QExtrudedTextMesh>
    
    int main(int argc, char *argv[])
    {
        QGuiApplication a(argc, argv);
    
        Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();
        view->setTitle(QStringLiteral("3D Text CPP"));
        view->defaultFrameGraph()->setClearColor(QColor("white"));
    
        auto *root = new Qt3DCore::QEntity();
    
        //Light
        Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(root);
        Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
        light->setColor("white");
        light->setIntensity(0.5);
        lightEntity->addComponent(light);
    
        //auto *textMaterial = new Qt3DExtras::QPhongMaterial(root);
        auto *textMaterial = new Qt3DExtras::QMetalRoughMaterial(root);
    
        auto *text = new Qt3DCore::QEntity(root);
        auto *textMesh = new Qt3DExtras::QExtrudedTextMesh();
        auto *textTransform = new Qt3DCore::QTransform();
    
        QFont font("Arial", 32, -1, false);
        textTransform->setTranslation(QVector3D(-2.45f, 2.0 * .5f, 0));
        textTransform->setScale(.8f);
    
        textMesh->setDepth(.25f);
        textMesh->setFont(font);
        textMesh->setText("TEST");
    
        //FOR PHONG MATERIAL
        //textMaterial->setDiffuse(QColor("white"));
        //textMaterial->setShininess(1.0);
        //textMaterial->setSpecular(QColor("white"));
    
        //FOR METAL
        textMaterial->setBaseColor(QColor("blue"));
        textMaterial->setMetalness(1.0);
        textMaterial->setRoughness(0.2);
        //textMaterial->setNormal(...)); //<-- what needs to come here?
    
        text->addComponent(textMaterial);
        text->addComponent(textMesh);
        text->addComponent(textTransform);
    
        // Camera
        float aspect = static_cast<float>(view->screen()->size().width()) / view->screen()->size().height();
    
        Qt3DRender::QCamera *camera = view->camera();
        camera->lens()->setPerspectiveProjection(65.f, aspect, 0.1f, 100.f);
        camera->setPosition(QVector3D(0, 1, 3));
        camera->setViewCenter(QVector3D(0, 1, 0));
        auto *cameraController = new Qt3DExtras::QOrbitCameraController(root);
        cameraController->setCamera(camera);
    
        view->setRootEntity(root);
        view->show();
        return a.exec();
    }
    

    How can I make get the metal material to work?

    Thanks!

    1 Reply Last reply
    0
    • DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by
      #2

      Solved on Windows by changing environment variable QT_OPENGL from the default angle to desktop.

      1 Reply Last reply
      0
      • EddyE Offline
        EddyE Offline
        Eddy
        wrote on last edited by Eddy
        #3

        @diracsbracket said in How to use QMetalRoughMaterial with QExtrudedTextMesh:

        //textMaterial->setNormal(...)); //<-- what needs to come here?

        the normal must be a texture. You can set it with a TextureLoader:

               normal: TextureLoader {
                    source: "qrc:/assets/textures/pbr-default/pbr-default-normal.png"
        
                    minificationFilter: Texture.LinearMipMapLinear
                    magnificationFilter: Texture.Linear
                    wrapMode {
                        x: WrapMode.ClampToEdge
                        y: WrapMode.ClampToEdge
                    }
                    generateMipMaps: true
                }
        

        Edit: this is QMl code of course. Just noticed you write C++. I don't seem to see the difference anymore. But you get the idea...

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved