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. Qt 3D QTextureImage cannot apply texture from png image
Forum Updated to NodeBB v4.3 + New Features

Qt 3D QTextureImage cannot apply texture from png image

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 2.6k 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.
  • B Offline
    B Offline
    blehotai85
    wrote on 12 Nov 2017, 19:59 last edited by
    #1

    Hi all,

    I am trying to apply a texture to a Sphere Mesh, but I'm getting a dark scene and the folowing error message:

    No QTextureImageData generated from functor yet, texture will be invalid for this frame

    I could not find any demos or documentation related to this topic, so maybe I'm doing it completely wrong, but so far I'm stuck and have no ide how to fix this.

    The code is this:

    // Sphere shape data
        Qt3DExtras::QSphereMesh *sphereMesh = new Qt3DExtras::QSphereMesh();
        sphereMesh->setRings(32);
        sphereMesh->setSlices(32);
        sphereMesh->setRadius(4);
    
        // Sphere mesh transform
        Qt3DCore::QTransform *sphereTransform = new Qt3DCore::QTransform();
        sphereTransform->setScale(1.0f);
        sphereTransform->setTranslation(QVector3D(0.0f, 0.0f, 0.0f));
        sphereTransform->setRotation(QQuaternion(1.0f, 0.0f, 0.0f, 0.0f));
    
        Qt3DRender::QTextureImage *diffuseTextureImage = new Qt3DRender::QTextureImage();
        diffuseTextureImage->setMirrored(false);
        diffuseTextureImage->setSource(QUrl(QStringLiteral("qrc:/textrue.png")));
    
        Qt3DExtras::QDiffuseSpecularMapMaterial *diffuseSpecularMaterial = new Qt3DExtras::QDiffuseSpecularMapMaterial();
        diffuseSpecularMaterial->diffuse()->addTextureImage(diffuseTextureImage);
     
       
        // Sphere
        auto m_sphereEntity = new Qt3DCore::QEntity(m_rootEntity);
        m_sphereEntity->addComponent(sphereMesh);
        m_sphereEntity->addComponent(diffuseSpecularMaterial);
        m_sphereEntity->addComponent(sphereTransform);
    
    
        return m_rootEntity;
    
    1 Reply Last reply
    1
    • ? Offline
      ? Offline
      A Former User
      wrote on 12 Nov 2017, 20:51 last edited by
      #2

      @blehotai85 said in Qt 3D QTextureImage cannot apply texture from png image:

      QStringLiteral("qrc:/textrue.png")));

      Hi! Maybe it's just a typo, "textrue".

      1 Reply Last reply
      1
      • B Offline
        B Offline
        blehotai85
        wrote on 14 Nov 2017, 04:35 last edited by
        #3

        Thank you, that was indeed a typo, but there is still no texture. The problem is that I couldn't find any tutorial or description about the usage of this, so I'm in the dark now. If anyone links some examples (not those officials in QML), I would really appreciate it.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on 14 Nov 2017, 04:50 last edited by
          #4

          Here's some code from my own Qt3D experiments. Can't test it right now but I think the following worked:

          texturedplaneentity.h

          #ifndef TEXTUREDPLANEENTITY_H
          #define TEXTUREDPLANEENTITY_H
          
          #include <QObject>
          #include <QSize>
          #include <QUrl>
          #include <Qt3DCore/QEntity>
          
          class TexturedPlaneEntity : public Qt3DCore::QEntity
          {
              Q_OBJECT
          public:
              explicit TexturedPlaneEntity(QSize size, QUrl const &textureSource, bool mirrored, Qt3DCore::QNode *parent = nullptr);
          };
          
          #endif // TEXTUREDPLANEENTITY_H
          

          texturedplaneentity.cpp

          #include "texturedplaneentity.h"
          
          #include <Qt3DExtras/QPlaneMesh>
          #include <Qt3DExtras/QNormalDiffuseSpecularMapMaterial>
          #include <Qt3DRender/QTextureImage>
          #include <Qt3DCore/QTransform>
          
          TexturedPlaneEntity::TexturedPlaneEntity(QSize size, const QUrl &textureSource, bool mirrored, Qt3DCore::QNode *parent)
              : QEntity(parent)
          {
              auto mesh = new Qt3DExtras::QPlaneMesh();
              mesh->setWidth(size.width());
              mesh->setHeight(size.height());
          
              auto material = new Qt3DExtras::QNormalDiffuseSpecularMapMaterial();
              auto textImg1 = new Qt3DRender::QTextureImage();
              auto textImg2 = new Qt3DRender::QTextureImage();
              auto textImg3 = new Qt3DRender::QTextureImage();
              textImg1->setSource(textureSource);
              textImg2->setSource(textureSource);
              textImg3->setSource(textureSource);
          
              textImg1->setMirrored(mirrored);
              textImg2->setMirrored(mirrored);
              textImg3->setMirrored(mirrored);
          
              material->diffuse()->addTextureImage(textImg1);
              material->normal()->addTextureImage(textImg2);
              material->specular()->addTextureImage(textImg3);
              material->setShininess(1.0);
              material->setAmbient("white");
          
              auto transform = new Qt3DCore::QTransform();
              // ...
          
              addComponent(mesh);
              addComponent(material);
              addComponent(transform);
          }
          
          B 1 Reply Last reply 14 Nov 2017, 08:51
          3
          • ? A Former User
            14 Nov 2017, 04:50

            Here's some code from my own Qt3D experiments. Can't test it right now but I think the following worked:

            texturedplaneentity.h

            #ifndef TEXTUREDPLANEENTITY_H
            #define TEXTUREDPLANEENTITY_H
            
            #include <QObject>
            #include <QSize>
            #include <QUrl>
            #include <Qt3DCore/QEntity>
            
            class TexturedPlaneEntity : public Qt3DCore::QEntity
            {
                Q_OBJECT
            public:
                explicit TexturedPlaneEntity(QSize size, QUrl const &textureSource, bool mirrored, Qt3DCore::QNode *parent = nullptr);
            };
            
            #endif // TEXTUREDPLANEENTITY_H
            

            texturedplaneentity.cpp

            #include "texturedplaneentity.h"
            
            #include <Qt3DExtras/QPlaneMesh>
            #include <Qt3DExtras/QNormalDiffuseSpecularMapMaterial>
            #include <Qt3DRender/QTextureImage>
            #include <Qt3DCore/QTransform>
            
            TexturedPlaneEntity::TexturedPlaneEntity(QSize size, const QUrl &textureSource, bool mirrored, Qt3DCore::QNode *parent)
                : QEntity(parent)
            {
                auto mesh = new Qt3DExtras::QPlaneMesh();
                mesh->setWidth(size.width());
                mesh->setHeight(size.height());
            
                auto material = new Qt3DExtras::QNormalDiffuseSpecularMapMaterial();
                auto textImg1 = new Qt3DRender::QTextureImage();
                auto textImg2 = new Qt3DRender::QTextureImage();
                auto textImg3 = new Qt3DRender::QTextureImage();
                textImg1->setSource(textureSource);
                textImg2->setSource(textureSource);
                textImg3->setSource(textureSource);
            
                textImg1->setMirrored(mirrored);
                textImg2->setMirrored(mirrored);
                textImg3->setMirrored(mirrored);
            
                material->diffuse()->addTextureImage(textImg1);
                material->normal()->addTextureImage(textImg2);
                material->specular()->addTextureImage(textImg3);
                material->setShininess(1.0);
                material->setAmbient("white");
            
                auto transform = new Qt3DCore::QTransform();
                // ...
            
                addComponent(mesh);
                addComponent(material);
                addComponent(transform);
            }
            
            B Offline
            B Offline
            blehotai85
            wrote on 14 Nov 2017, 08:51 last edited by
            #5

            @Wieland Really appreciate it. I will try out later today. Thank you!

            1 Reply Last reply
            0
            • B Offline
              B Offline
              blehotai85
              wrote on 14 Mar 2018, 18:16 last edited by
              #6

              Just to close this topic, I found that the code posted here seemed to be okay. I tried it again just recently with Qt 5.9.4 and a notebook with a GPU capable of OpenGL 4.5 and it ran smoothly. I think my old PC with intel GMA / driver was the problem. Thanks everyone for the comments.

              1 Reply Last reply
              1

              • Login

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