Results 1 to 10 of 10

Thread: QOpenGL QTimer, how do I animate this?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QOpenGL QTimer, how do I animate this?

    Quote Originally Posted by JerichoJosh View Post
    Could you give me an example on how to do this, I have no clue how to implement that?
    Have a look at the Animation Framework docs.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Dec 2013
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QOpenGL QTimer, how do I animate this?

    Could you help me to implement a QTimer?
    the documentation you gave me remains too abstract for me, and mostly related to qPainter

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QOpenGL QTimer, how do I animate this?

    I think what you will have to do is change values in your time slot and then call updateGL()

    That will result in another call to paintGL() in which you can update your GL data.

    Cheers,
    _

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QOpenGL QTimer, how do I animate this?

    Quote Originally Posted by JerichoJosh View Post
    Could you help me to implement a QTimer?
    the documentation you gave me remains too abstract for me, and mostly related to qPainter
    There is not a single reference to QPainter in the documentation I gave you.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: QOpenGL QTimer, how do I animate this?

    Use QOpenGLWindow with the frameSwapped signal. This is my example with Qt 6.7 that prints delta time to the console:

    main.cpp

    Qt Code:
    1. #include <QtCore/QElapsedTimer>
    2. #include <QtGui/QOpenGLFunctions>
    3. #include <QtGui/QSurfaceFormat>
    4. #include <QtOpenGL/QOpenGLWindow>
    5. #include <QtWidgets/QApplication>
    6.  
    7. class OpenGLWindow : public QOpenGLWindow, private QOpenGLFunctions
    8. {
    9. public:
    10.  
    11. OpenGLWindow()
    12. {
    13. setTitle("OpenGL ES 2.0, Qt6, C++");
    14. resize(380, 380);
    15.  
    16. QSurfaceFormat surfaceFormat;
    17. surfaceFormat.setSwapInterval(1);
    18. connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
    19. setFormat(surfaceFormat);
    20. }
    21.  
    22. private:
    23.  
    24. void initializeGL() override
    25. {
    26. initializeOpenGLFunctions();
    27. glClearColor(0.2f, 0.2f, 0.2f, 1.f);
    28. m_elapsedTimer.start();
    29. }
    30.  
    31. void resizeGL(int w, int h) override
    32. {
    33. glViewport(0, 0, w, h);
    34. }
    35.  
    36. void paintGL() override
    37. {
    38. float dt = m_elapsedTimer.elapsed() / 1000.f;
    39. m_elapsedTimer.restart();
    40. qDebug() << dt;
    41. glClear(GL_COLOR_BUFFER_BIT);
    42. }
    43.  
    44. private:
    45. QElapsedTimer m_elapsedTimer;
    46. };
    47.  
    48. int main(int argc, char *argv[])
    49. {
    50. QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL);
    51. QApplication app(argc, argv);
    52. OpenGLWindow w;
    53. w.show();
    54. return app.exec();
    55. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jun 2024
    Posts
    1
    Qt products
    Qt Jambi
    Platforms
    Android

    Default Re: QOpenGL QTimer, how do I animate this?

    How can the drawing methods in the "Hello-OpenGL" example be used for animation?
    a happy girl

Similar Threads

  1. <qopengl.h> library .lib?
    By giugio in forum Qt Programming
    Replies: 5
    Last Post: 10th September 2013, 10:52
  2. QOpenGL in threads
    By wydesenej in forum Qt Programming
    Replies: 4
    Last Post: 22nd May 2013, 15:11
  3. Example Q, FLTKt and OpenGL without using QOpenGL
    By giorgik in forum Qt Programming
    Replies: 8
    Last Post: 27th December 2012, 18:56
  4. Replies: 15
    Last Post: 4th August 2012, 19:11
  5. how to use QTimer to animate QSlider
    By mike b in forum Newbie
    Replies: 1
    Last Post: 11th May 2010, 05:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.