Adriel Jr
Adriel Jr

Reputation: 2681

How can I load a QPaintedTextureImage into a QTextureMaterial?

I am using Qt3D to create a 360 deg panorama viewer where the image in equirectangular format is loaded over the mesh of a sphere with negative radius. The problem is that I need to load the texture from memory, instead of a file.

In order to achieve that, I developed a custom QPaintedTextureImage with paint() overloaded to draw from a QImage. It works, but only when plugged into a QDiffuseMapMaterial. Since I don't want any light effect (just the original color of the pixels) it seems that QTextureMaterial would be the right choice, but I don't know how to do that.

Any idea?

Upvotes: 0

Views: 278

Answers (1)

Adriel Jr
Adriel Jr

Reputation: 2681

Got it!

class MyQPaintedTextureImage : public Qt3DRender::QPaintedTextureImage
{
private:
    QImage image;
public:
    void setImage(QImage &i){
        image = i;
        setSize(i.size());
    }
    virtual void paint(QPainter *painter) override{
        painter->drawImage(0, 0, image);
    }
};

And then:

auto *image = new MyQPaintedTextureImage;
image->setImage(i);
auto *planeMaterial = new Qt3DExtras::QTextureMaterial;
planeMaterial->texture()->addTextureImage(image);
m_sphereEntity->addComponent(planeMaterial);

Upvotes: 2

Related Questions