Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [solved] Qt and OpenGL
QtWS25 Last Chance

[solved] Qt and OpenGL

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 2 Posters 2.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.
  • S Offline
    S Offline
    Speechless
    wrote on last edited by
    #1

    Hi Guys!

    I'm trying to use the power of the OpenGL on a Colibri T20 from Toradex. The card is running Linux (Angstrom) with X11 (Xorg).

    I've developped a small piece of code (which is running fine on Windows) with both QWidget and QGLWidget. It's a simple animation on a picture (fade-in/fade-out) When I'm running the version with the QWidget I can see my processor up to 20% and when I'm running it with the QGLWidget, the processor activity looks like the ECG from a reality TV star, so I concluded that my usage of the QGLWidget is correct. :-)

    The problem is when I'm running the code on the card: the animation I've created is sloooooooooooooooooow (with both QGLWidget and QWidget)

    So my question is: Am I really using the hardware accelaration or not? How can I test it? Should I have receive an error from my project during the compilation if OpenGL wasn't installed on the card? Or, is my code optimized? (my opinion: my code is not optimised at all :-) )

    Here is the code of my test widget:

    @#include "glwidget.h"
    #include "QDebug"

    GLWidget::GLWidget(Helper *helper, QWidget *parent)
    : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), helper(helper)
    {
    elapsed = 1;
    reverse = false;
    }

    void GLWidget::animate()
    {
    //elapsed = (elapsed + qobject_cast<QTimer*>(sender())->interval()) % 1000;
    if(reverse)
    elapsed = elapsed + 0.01;
    else
    elapsed = elapsed - 0.01;

    if(elapsed <= 0 && reverse == false)
        reverse = true;
    else if(elapsed >= 1 && reverse == true)
        reverse = false;
    
    repaint();
    

    }

    void GLWidget::paintEvent(QPaintEvent *event)
    {
    QPainter painter;
    painter.begin(this);
    painter.setOpacity(elapsed);
    painter.setRenderHint(QPainter::Antialiasing);
    helper->paint(&painter, event, elapsed);

    painter.end();
    

    }@

    And here the repaint's call

    @GLWidget *openGL = new GLWidget(&helper, this);

    this->setCentralWidget(openGL);

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), openGL, SLOT(animate()));
    timer->start(10);@

    Thanks a looooooot!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      I'm not sure I'm following you right. Since you want to do OpenGL why are you using paintEvent ?

      Also, you are trying to update at 100fps which might be a bit optimistic for an embedded board.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Speechless
        wrote on last edited by
        #3

        Hi,

        Thanks for welcoming me on the forum and for your answer!

        I followed a tutorial on line to create this widget because I've never worked with OpenGL and paint functions. Should I use paintGL and QGLPainter instead?

        I've try to turn down to 10fps, the result seems the same... For my fade-in/out functions, I'm using the painter's setOpacity function, is it the right way?

        What I want to do is simple, just a smooth fade-in/out on a picture :-)

        Thanks for you answer!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then you might be overcomplicating things, what about this:

          • QLabel -> for your image
          • QGraphicsOpacityEffect -> self-explaining
          • QPropertyAnimation -> to animate the QGraphicsOpacityEffect

          This way everything is automated for you

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Speechless
            wrote on last edited by
            #5

            Thanks, but actually I've started to use OpenGL directly because my first try was QPropertyAnimation and QGraphicsOpacityEffect and the result wasn't good too.

            But, good news! I've found a solution... The problem was the picture it self... I used a too big one and because i'm lazy i downscaled the picture to see it entirely on the screen... So I've changed the picture by a picture of 1920x1080 and... Wow, at 100fps, it's smooth as hell! And it use only 5 to 8 percent of the processor!

            Sorry for this thread... My fault... But I've learned a lot and maybe my code will be usefull for somebody else :-)

            Thanks again!

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You're welcome !

              Don't be afraid to ask question :)

              Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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