Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25

Thread: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

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

    Default Re: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    Does your application do anything apart from performing the animation at the same time?

    BTW. I'm afraid updateGL() only schedules a repaint, not performs it immediately, so your calculations are not really that precise. As for the 20ms problem - I have no idea... maybe there is some vblank issue related or something. Or maybe you simply didn't repeat the tests enough number of times.
    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. The following user says thank you to wysota for this useful post:

    ricardo (12th August 2009)

  3. #22
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    Quote Originally Posted by wysota View Post
    Does your application do anything apart from performing the animation at the same time?

    BTW. I'm afraid updateGL() only schedules a repaint, not performs it immediately, so your calculations are not really that precise. As for the 20ms problem - I have no idea... maybe there is some vblank issue related or something. Or maybe you simply didn't repeat the tests enough number of times.
    Nope. Just update my world and render it.

    I read on docs:
    "If you need to trigger a repaint from places other than paintGL() (a typical example is when using timers to animate scenes), you should call the widget's updateGL() function."
    From: http://doc.trolltech.com/4.5/qglwidget.html#paintGL

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

    Default Re: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    Quote Originally Posted by ricardo View Post
    I read on docs:
    "If you need to trigger a repaint from places other than paintGL() (a typical example is when using timers to animate scenes), you should call the widget's updateGL() function."
    From: http://doc.trolltech.com/4.5/qglwidget.html#paintGL
    Which still doesn't determine when paintGL() will be called after a call to updateGL(). But I just checked in the code - the redraw is immediate.
    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. The following user says thank you to wysota for this useful post:

    ricardo (12th August 2009)

  6. #24
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Wink Re: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    Hi friends!

    I think I found a way. just a WHILE(1) and use qApp->processEvents() to avoid a blocked UI. This code is executed when PLAY is pressed. There are no timers.

    Qt Code:
    1. // simulate it for 10 seconds
    2. m_rendered_frames=0;
    3. m_time.start();
    4. while (m_time.elapsed()<=10000) {
    5. QTime now;
    6. now.start();
    7. qApp->processEvents();
    8. m_current_level->Update(0);
    9. m_gl_drawer->updateGL();
    10. m_rendered_frames++;
    11. // sleep a while
    12. if (SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed()>0) {
    13. QTest::qSleep(SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed());
    14. }
    15. }
    16. // info
    17. float fps=m_rendered_frames/10.0;
    18. QString m=QString("FPS: %1. rendered frames: %2. Timer interval (ms): %3.").arg(fps).arg(m_rendered_frames).arg(SIMULATION_UPDATE_INTERVAL_IN_MS);
    19. QMessageBox::warning(this, "Warning", m);
    To copy to clipboard, switch view to plain text mode 

    It works properly. What do you think?

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

    Default Re: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    Event processing is sparse, keys might not be responding or might respond with a delay. That's not a good way to do it. But if it suits your needs...
    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.


Similar Threads

  1. Retrieval of frame rate in Phonon.
    By Theo Adams in forum Qt Programming
    Replies: 2
    Last Post: 6th July 2010, 19:00
  2. Replies: 1
    Last Post: 23rd April 2009, 09:05
  3. Frame rate problem
    By MrShahi in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2008, 23:06
  4. Change frame rate
    By superutsav in forum General Programming
    Replies: 1
    Last Post: 3rd August 2006, 21:02

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
  •  
Qt is a trademark of The Qt Company.