2d image in a qt3d scene



  • Hi, I am trying to include a 2d image in my qt3d scene node. I do not want to open the image in a separate window. I want to include it in the scene where my camera and cube is lying. I tried to use QPixmap.

    @void CubeView::paintGL(QGLPainter *painter)
    {
    cube->draw(painter);
    QPixmap *img;
    img->load("D:\opencv\blackcircle.jpg");
    cube->draw(img);
    }@

    How can I include it in my scene? Thanks


  • Moderators

    Hi,

    Are you new to c++? You are calling load on an uninitialized pointer.

    Also what type is cube? I doubt that it has draw() methods that take both a painter and a pixmap. These are separate concepts.

    Do you want to texture the cube with that pixmap or display it separately on a piece of geometry?



  • Cube is an object of class cubeview.
    @#ifndef CUBEVIEW_H
    #define CUBEVIEW_H

    #include "qglview.h"

    QT_BEGIN_NAMESPACE
    class QGLSceneNode;
    QT_END_NAMESPACE

    class CubeView : public QGLView
    {
    Q_OBJECT
    public:
    CubeView(QWindow *parent = 0);
    ~CubeView();

    protected:
    void paintGL(QGLPainter *painter);

    private:
    QGLSceneNode *cube;
    QGLTexture2D *texture;
    };

    #endif@

    The following code puts the image as a texture on the cube.

    @#include "cubeview.h"
    #include "qglbuilder.h"
    #include "qglcube.h"

    #include <QtCore/qurl.h>

    CubeView::CubeView(QWindow *parent)
    : QGLView(parent)
    , cube(0)
    , texture(0)
    {
    QGLBuilder builder;
    builder << QGL::Faceted << QGLCube(1.5f);
    cube = builder.finalizedSceneNode();

    QGLMaterial *mat = new QGLMaterial;
    mat->setColor(QColor(170, 202, 0));
    QUrl url;
    url.setPath(QLatin1String(":/qtlogo.png"));
    url.setScheme(QLatin1String("file"));
    mat->setTextureUrl(url);
    texture = mat->texture();
    cube->setMaterial(mat);
    
    cube->setEffect(QGL::LitDecalTexture2D);
    

    }

    CubeView::~CubeView()
    {
    texture->cleanupResources();
    delete cube;
    }

    void CubeView::paintGL(QGLPainter *painter)
    {
    painter->modelViewMatrix().rotate(45.0f, 1.0f, 1.0f, 1.0f);
    cube->draw(painter);
    }
    @

    I want to display an image in the scene. But not as a texture on the cube. How should I do it?

    [edit: corrected coding tag position SGaist]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.