Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved QDiffuseSpecularMaterial diffuse texture

    General and Desktop
    2
    6
    264
    Loading More Posts
    • 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.
    • J
      JanWillemsen last edited by

      Hi,

      I would like to use a texture for the diffuse component of a QDiffuseSpecularMaterial. In the documentation I find for the diffuse property:

      "Holds the diffuse color of the material that is emitted for rough surface reflections with the lights. This can be either a plain color value or a texture."

      but how do I give it a texture (loaded from a png on disk)? It expects a QVariant...

      Jan

      1 Reply Last reply Reply Quote 0
      • K
        kippa last edited by

        Just found this issue here. I am also having the same problem. QVariant is not happy with QTexture2D.

        I am Using 5.12.3 at the moment, but maybe I'd better check 5.13.
        Kipp

        K 1 Reply Last reply Reply Quote 0
        • K
          kippa @kippa last edited by

          @kippa Same on 5.13.0. I must be missing something.

          1 Reply Last reply Reply Quote 0
          • J
            JanWillemsen last edited by

            @kippa After a lot of trying, I succeeded by doing the following

            Qt3DExtras::QDiffuseSpecularMaterial* material = new Qt3DExtras::QDiffuseSpecularMaterial(_renderData);
            Qt3DRender::QTexture2D* tex = new Qt3DRender::QTexture2D(_renderData);
            SVGTexture* texIm = new SVGTexture(texture, static_cast<int>(width), static_cast<int>(height), tex); //Subclass of QPaintedTextureImage with SvgRenderer to use an svg as texture
            tex->addTextureImage(texIm);
            texIm->update();
            material->setDiffuse(QVariant::fromValue(qobject_cast<QObject*>(tex)));
            

            Hope this helps.

            Jan

            1 Reply Last reply Reply Quote 0
            • K
              kippa last edited by

              JanWillemsen Thanks. Of course it's the cast. Works like a charm. Thanks for getting me out of my mental quicksand. Perhaps QVariant will become qabstracttexture aware someday.

              1 Reply Last reply Reply Quote 0
              • K
                kippa last edited by

                I eventually found this to work for me

                texture = new Qt3DRender::QTexture2D();
                material = new Qt3DExtras::QDiffuseSpecularMaterial();
                material->setAlphaBlendingEnabled(true);
                material->setAmbient(QColor(0xff,0xff,0xff,0x00));
                // SymbolImage is my subclass of qabstracttexture
                img = new SymbolImage(name, material, blah, blah, blah,  blah,  blah);
                texture->addTextureImage(img);
                // the two textures are identical for my work
                material->setDiffuse(QVariant::fromValue(texture));
                material->setSpecular(QVariant::fromValue(texture));
                

                So just QVariant::fromValue().

                Then later upon a callback:

                /// assume diffuse is same as specular, or use specular
                QTexture2D *t = material->diffuse().value<QTexture2D*>();
                SymbolImage *s = static_cast<SymbolImage*>(t->textureImages().first());
                

                That's what I ended up using.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post