Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved] - Embed OpenGl rendering
QtWS25 Last Chance

[solved] - Embed OpenGl rendering

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 3 Posters 5.2k 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.
  • Y Offline
    Y Offline
    yan_
    wrote on last edited by
    #1

    Hi.

    I try to had a "WebGl-OpenGl api to qml throw a plugin":http://www.youtube.com/user/QExtend#p/c/1FD514E2B24011DB/1/bxcbolOuFeY and i try to find the best method to embed OpenGl rendering .

    I test 3 methods :

    1- render to a QGLPixelBuffer and get image with toImage(). Good performance but slow for big image (Edit: depend on hardware used)

    2- use QGlCOntext to a Pixmap. Bad performance.

    3- use OPenGl graphics system, render scene to a QGLPixelBuffer. I try to draw a rectangle with texture from QGLPixelBuffer in QDeclarativeItem::paint but it's doesn't work :(

    Do you know other solution ? I think method 3 could be better but i don't find how use correctly QDeclarativeItem::paint with Opengl call.

    "QExtend":http://www.developpez.net/forums/d906429/c-cpp/bibliotheques/qt/naissance-projet-qextend/
    "QEXtend Video":http://www.youtube.com/user/QEx...

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thorbjorn
      wrote on last edited by
      #2

      I think your best option is to make sure the QDeclarativeView is using a GLWidget as its viewport (if using qmlviewer, pass -opengl). Then you can rely on OpenGL calls simply working in your paint implementation. It will also allow you to make use of primitives provided by the Qt 3D project ("http://qt.gitorious.org/qt-labs/qt3d":http://qt.gitorious.org/qt-labs/qt3d).

      Embedding an OpenGL view inside a non-OpenGL QDeclarativeView is just getting messy and would indeed be hard to make perform well I think. Especially if you want to be able to perform transformations on it.

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yan_
        wrote on last edited by
        #3

        [quote author="Thorbjørn Lindeijer" date="1285697279"]I think your best option is to make sure the QDeclarativeView is using a GLWidget as its viewport (if using qmlviewer, pass -opengl). Then you can rely on OpenGL calls simply working in your paint implementation. It will also allow you to make use of primitives provided by the Qt 3D project ("http://qt.gitorious.org/qt-labs/qt3d":http://qt.gitorious.org/qt-labs/qt3d).[/quote]
        I try draw a rectangle in paint method when opengl is activate.

        @void Canvas::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
        {
        static QTime t(QTime::currentTime());
        static double mean(0.);
        static int nb = 0;
        ++nb;
        if(t.elapsed()>1000 )
        {
        mean = 1000.*nb/t.elapsed();
        t.restart();
        nb = 0;
        }
        p->setBrush(m_background);
        p->setPen(Qt::NoPen);
        p->drawRect(boundingRect().toRect());
        p->drawPixmap(0,0,m_cache);

        glBegin(GL_QUADS);
           glVertex3d(0, 0,  0);
           glVertex3d(0,  100,  0);
           glVertex3d( 100,  100,  0);
           glVertex3d( 100, 0,  0);
        glEnd();
        
        p->setPen(Qt::red);
        p->setFont(QFont("Tahoma",20,QFont::Bold));
        p->drawText(10,25,QString::number(mean,'g',4));
        

        }@
        A corresponding rectangle appear like a translucent quads.

        If i try to use a color or a texture, the quad display bug.

        I don't understand why.

        I'll see qt3d code.

        [quote author="Thorbjørn Lindeijer" date="1285697279"]
        Embedding an OpenGL view inside a non-OpenGL QDeclarativeView is just getting messy and would indeed be hard to make perform well I think. Especially if you want to be able to perform transformations on it.[/quote]
        QGlPixelBuffer with toImage work fine with good pc... It's a first solution. But a full OpenGl solution will certainly better.

        "QExtend":http://www.developpez.net/forums/d906429/c-cpp/bibliotheques/qt/naissance-projet-qextend/
        "QEXtend Video":http://www.youtube.com/user/QEx...

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          Have you tried using "beginNativePainting()":http://doc.trolltech.com/4.7/qpainter.html#beginNativePainting and endNativePainting() to wrap your raw GL code?

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            yan_
            wrote on last edited by
            #5

            [quote author="mbrasser" date="1285721884"]Have you tried using "beginNativePainting()":http://doc.trolltech.com/4.7/qpainter.html#beginNativePainting and endNativePainting() to wrap your raw GL code? [/quote]
            Cool. I don't see these functions. I'll test tonight.

            In my last test, use OpenGl works very fine if i d'ont use QPainter in the paint method and if my item is alone. So beginNativePainting seem to be what i want.

            "QExtend":http://www.developpez.net/forums/d906429/c-cpp/bibliotheques/qt/naissance-projet-qextend/
            "QEXtend Video":http://www.youtube.com/user/QEx...

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              yan_
              wrote on last edited by
              #6

              yatta

              After understand how use QGLPixelBuffer with different context, It's work very fine ^^

              thanks.

              (ps : how tag a post resolved?)

              "QExtend":http://www.developpez.net/forums/d906429/c-cpp/bibliotheques/qt/naissance-projet-qextend/
              "QEXtend Video":http://www.youtube.com/user/QEx...

              1 Reply Last reply
              0
              • ? This user is from outside of this forum
                ? This user is from outside of this forum
                Guest
                wrote on last edited by
                #7

                [quote author="yan" date="1285792561"]
                (ps : how tag a post resolved?)[/quote]

                Just add a tag 'solved' to the post

                1 Reply Last reply
                0
                • Y Offline
                  Y Offline
                  yan_
                  wrote on last edited by
                  #8

                  [quote author="chetankjain" date="1285792948"] [quote author="yan" date="1285792561"]
                  (ps : how tag a post resolved?)[/quote]

                  Just add a tag 'solved' to the post

                  [/quote]

                  add solved to the title??

                  "QExtend":http://www.developpez.net/forums/d906429/c-cpp/bibliotheques/qt/naissance-projet-qextend/
                  "QEXtend Video":http://www.youtube.com/user/QEx...

                  1 Reply Last reply
                  0
                  • ? This user is from outside of this forum
                    ? This user is from outside of this forum
                    Guest
                    wrote on last edited by
                    #9

                    yes, you could also add [Solved] to the title, along with the tag :)

                    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