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. 2d image in a qt3d scene
Qt 6.11 is out! See what's new in the release blog

2d image in a qt3d scene

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k 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.
  • S Offline
    S Offline
    sunil.nair
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sunil.nair
        wrote on last edited by
        #3

        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]

        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