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. QDiffuseSpecularMaterial diffuse texture

QDiffuseSpecularMaterial diffuse texture

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 813 Views
  • 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 Offline
    J Offline
    JanWillemsen
    wrote on last edited by
    #1

    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
    0
    • K Offline
      K Offline
      kippa
      wrote on last edited by
      #2

      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
      0
      • K kippa

        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 Offline
        K Offline
        kippa
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JanWillemsen
          wrote on last edited by
          #4

          @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
          0
          • K Offline
            K Offline
            kippa
            wrote on last edited by
            #5

            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
            0
            • K Offline
              K Offline
              kippa
              wrote on last edited by
              #6

              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
              0

              • Login

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