Page 1 of 2 12 LastLast
Results 1 to 20 of 25

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

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

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

    Hi dudes!

    I have a little problem. I'm doing a level editor where level can be created and played in real time. Now I'm using a QTimer to update my objects (position and logic) and render them (using updateGL from QGLWidget) when somebody wants to play a level.

    But using a QTimer is not going well.

    "Windows 98 has 55 millisecond accuracy; other systems that we have tested can handle 1 millisecond intervals."
    http://doc.trolltech.com/4.5/timers.html

    It seems Windows XP has the same problem, just a 55 ms accuracy. BTW, I use VS2005, WinXP and Qt 4.5 on a good PC

    The problem is that 55 ms means 18 frames per second, which is not as good as I thought. For gaming I will require at least 30 FPS (60 FPS even better)

    Do you have any suggestion or idea?

    Do you believe I should use threads or consider them? I dont know too much about theads, What cautions should I take to avoid problems with my UI? (I mean, shared variables or that)

    Thanks a lot for your help and time.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    I don't see where threads would help in your situation... If you want, you may constantly call updateGL() on your widget and you will get maximum possible framerate. But the problem is generally in your system - XP should handle resolutions larger than 55ms fine. The limitation of 98 comes from the design of the system which was obviously changed in later Windows systems. How did you test that your XP also has the 55ms limitation? Did you try the same program on different systems?
    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.


  3. #3
    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
    I don't see where threads would help in your situation... If you want, you may constantly call updateGL() on your widget and you will get maximum possible framerate. But the problem is generally in your system - XP should handle resolutions larger than 55ms fine. The limitation of 98 comes from the design of the system which was obviously changed in later Windows systems. How did you test that your XP also has the 55ms limitation? Did you try the same program on different systems?
    Thanks for reply.

    I did a test for you.

    Using QTimer with 20 ms and a QTime to know when my app started:

    m_timer=new QTimer(this);
    m_timer->setInterval(20);
    connect(m_timer, SIGNAL(timeout()), this, SLOT(TimerFired()));

    void CEditor::TimerFired() {
    qDebug() << "t=" << m_time.elapsed();
    }

    I got these results, which obviusly are not expected (it should be 9578, 9598...)
    t= 9578
    t= 9610
    t= 9641
    t= 9672
    t= 9703
    t= 9735
    t= 9766
    t= 9797
    t= 9828
    t= 9860
    t= 9891
    t= 9922
    t= 9953
    t= 9985
    t= 10016
    t= 10047
    t= 10078
    t= 10110
    t= 10141
    t= 10172
    t= 10203
    t= 10235

    Any idea?
    I have a QuadCore 2.4 GHz and an ATI HD3870, so I don't thinks is because my computer.
    Do you all know what going on is? Note this time I am not redrawing and updating my game on TimerFired, so it is even more strange.
    Maybe it is because I'm using DEBUG mode, I don't know.

    Thanks a lot for your time.

  4. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    What you're running into is a limitation of the (type of) operating system. OSes made for people aren't too strict on timing because there is no need for it.

    Also remember two things:
    1. Debug mode generally makes your app slower
    2. Outputting stuff to console makes your app slower
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  5. #5
    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 franz View Post
    What you're running into is a limitation of the (type of) operating system. OSes made for people aren't too strict on timing because there is no need for it.

    Also remember two things:
    1. Debug mode generally makes your app slower
    2. Outputting stuff to console makes your app slower
    Thanks for reply.

    I did that, relese mode and not writing anything on console. I wrote this test code:

    Qt Code:
    1. void CEditor::TimerFired() {
    2. static int rendered_frames=0;
    3. // draw here whatever
    4. m_current_level->Update(0);
    5. m_gl_drawer->updateGL();
    6. rendered_frames++;
    7.  
    8. // after 10 seconds
    9. int total_time=10000;
    10. if (m_time.elapsed()>total_time) {
    11. float fps=rendered_frames/(0.001*total_time);
    12. QString m=QString("FPS: %1. rendered frames: %2. Timer interval (ms): %3. Total time (ms): %4").arg(fps).arg(rendered_frames).arg(SIMULATION_UPDATE_INTERVAL_IN_MS).arg(total_time);
    13. QMessageBox::warning(this, "Warning", m);
    14. m_timer->stop();
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    That code will simulate my game for just 10 seconds. 20 ms interval (SIMULATION_UPDATE_INTERVAL_IN_MS) should be 50 frames per sencod. As you can see in this picture, something is wrong.



    So, what do you recommend me? Does anyone know why this happens?

    Thanks a lot.

  6. #6
    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

    Any idea? I really have no idea why I cann`t get enough FPS.
    Thanks.

  7. #7
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

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

    Off course, Qt signal and slot mechanism is also applied to qtimer's timeout signal.
    So you're limited to qapplication's event loop to take care this signal in time. No signal must be handled in time off course.
    I experienced 2000 threads and believe me that after a few seconds i hardly get any signals, moreover i had never get timeout signal!
    so if you want to make it more accurate, use another thread
    and don't use ALARM signal as it's system wide. use "nanosleep" or "select" and give timeout parameter as you wish.

    i mean, don't use qtimer if you're doing such kind of processing. Call critical functions with system calls(whatever applies to windows). qtimer is bound to event queue which is not accurate.

    so i changed my 2000 threaded code to "select" version then it's running flawlessly now.

    Windows system may give you built-in easy to use timer but functions that i mentioned before are for Linux.

    And off course these accuracy brings complexity to your application.
    Last edited by hayati; 11th August 2009 at 13:17.

  8. The following user says thank you to hayati for this useful post:

    ricardo (11th August 2009)

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    This is all wrong. The problem is not the limitation of timers, the problem is that rendering takes time as well. If you set a timeout of a timer to 100ms, then after 1 second you might get from 0 to 10 timeouts (inclusive) and that's perfectly normal. Instead of having a static timeout, one should save the time of last timeout and after the rendering of the frame is done, correct the timeout for next frame to compensate for system being more or less busy.

    Qt Code:
    1. void MyClass::renderFrame(){
    2. QTime now;
    3. now.start();
    4. renderMe();
    5. QTimer::singleShot(20-now.elapsed(), this, SLOT(renderFrame())); //should get around 50 FPS
    6. }
    To copy to clipboard, switch view to plain text mode 

    This should get more accurate timing (although there is still place for improvement which is left as the task to the reader).
    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.


  10. The following user says thank you to wysota for this useful post:

    ricardo (11th August 2009)

  11. #9
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

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

    Unfortunately this is not true!
    If system is busy in doing someting you may never get timeout calls at all.
    and off course painting is a long operation but what is opengl is for.

    i mean there is an extra latency for qeventloop which is explained by trolltech's.


    may be this thread is useful for explaining latency.

    link is here:

    http://www.archivum.info/qt-interest...L_:_QEventLoop

    and this link:

    http://www.archivum.info/qt-interest...tes_for_OpenGL

    thanks.

  12. The following user says thank you to hayati for this useful post:

    ricardo (11th August 2009)

  13. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    Quote Originally Posted by hayati View Post
    If system is busy in doing someting you may never get timeout calls at all.
    That's exactly what I'm saying. After 10 times the timeout value you may get from 0 to 10 timeouts depending on what is happening in the system.

    and off course painting is a long operation but what is opengl is for.
    You mean you have only fully OpenGL applications in your system?

    The latency of the loop is obvious (it does "something", so it introduces a delay), but it is nothing compared to latency of the whole system. Try running a few "while(1);" applications and at the same time run a simple application with a timer triggering at 10Hz, regardless if you are using OpenGL or not.

    Bottom line is - without a real time operating system you may never trust any timers - it is a tool, not a panaceum.
    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.


  14. The following user says thank you to wysota for this useful post:

    ricardo (11th August 2009)

  15. #11
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

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

    i think second link of my previous post also discusses same issue. That's why i gave these links from trolls' side.

    At the end both side agrees on QTimer is not well suited for that kind of update triggering.

    Thanks

  16. The following user says thank you to hayati for this useful post:

    ricardo (11th August 2009)

  17. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    Quote Originally Posted by hayati View Post
    At the end both side agrees on QTimer is not well suited for that kind of update triggering.
    It's fine, it just needs to be used properly. Using sleep() or any of its variants wouldn't change a thing.
    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.


  18. The following user says thank you to wysota for this useful post:

    ricardo (11th August 2009)

  19. #13
    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

    @hayati: Are you telling I should use a thread? USually, common games only use a thread in their main loop.
    Useful links, Now I reading them, thanks.
    If I use a thread to update and render my game, does this create any multithreaded problem? I mean, shared variables... (I'm not an expert in MT apps)
    If I use a thread, can I have issues with keyboard and mouse events?



    @wysota: Evidently updating and rendering takes time, but I read this form docs: (constant intervals)
    "The QTimer class provides a high-level programming interface for timers. To use it, create a QTimer, connect its timeout() signal to the appropriate slots, and call start(). From then on it will emit the timeout() signal at constant intervals."
    Did you try your method? are you sure it works? I will try it tomorrow.

    "without a real time operating system you may never trust any timers - it is a tool, not a panaceum."
    I don't think I need that accuracy, just about 45 and 55 FPS would be nice to create a good simulation.




    What do you all thinks about http://www.libqglviewer.com/?
    I didn't use it, but reading some docs I read
    http://www.libqglviewer.com/features.htm
    "Possible animation of the scene at a given frame rate"

    Does anyone use that library?


    Thanks a lot for help.

  20. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    Quote Originally Posted by ricardo View Post
    @wysota: Evidently updating and rendering takes time, but I read this form docs: (constant intervals)
    "The QTimer class provides a high-level programming interface for timers. To use it, create a QTimer, connect its timeout() signal to the appropriate slots, and call start(). From then on it will emit the timeout() signal at constant intervals."
    "Constant intervals" is an approximation. Timers are not guaranteed to fire under stress on non-realtime operating systems. There's really nothing to discuss.

    Did you try your method? are you sure it works?
    Why shouldn't it work? It's an adaptive timer which makes the frame rate more stable than using a non-adaptive timer.

    "without a real time operating system you may never trust any timers - it is a tool, not a panaceum."
    I don't think I need that accuracy, just about 45 and 55 FPS would be nice to create a good simulation.
    You can't get even that. There is no guarantee - the kernel might preempty your process at any time for any amount of time (like 10 minutes, if it felt like doing so - of course usually it doesn't). There is just no way you can get a timeout during that period.

    You have to stick with "most of the time in normal conditions you will get 20-60ms accuracy" (consider the difference between resolution and stability of the rate). But you can compensate for "lost frames" by using adaptive timers (and even skipping rendering frames to catch up) - in reality redrawing framerate is not important at all (as long as it's over 16fps so that your eye can perceive it as animation - the brain will interpolate properly) - it is important that the logic is updated fluently (to prevent the game from "lagging behind") which is completely enough in your case. You can even adapt the complexity of scene rendering to compensate lags. Remember that computer graphics is mostly about cheating.

    And to stress again - using another thread will only make things worse as the system will have to context-switch between threads thus losing more time (for a moment ignoring the fact you can't paint from worker threads in Qt) doing completely nothing from your application's point of view. You can use sleep/msleep/nanosleep in the main thread just as well but it won't change the fact that these functions only guarantee that you will not be woken before the given time elapses, nothing more.
    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.


  21. The following user says thank you to wysota for this useful post:

    ricardo (12th August 2009)

  22. #15
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

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

    I am interested in FPS when you don't use timer - just loop which will render as fast as it can. How many fps can you achieve in that way?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  23. The following user says thank you to faldzip for this useful post:

    ricardo (12th August 2009)

  24. #16
    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
    "Constant intervals" is an approximation. Timers are not guaranteed to fire under stress on non-realtime operating systems. There's really nothing to discuss.


    Why shouldn't it work? It's an adaptive timer which makes the frame rate more stable than using a non-adaptive timer.


    You can't get even that. There is no guarantee - the kernel might preempty your process at any time for any amount of time (like 10 minutes, if it felt like doing so - of course usually it doesn't). There is just no way you can get a timeout during that period.

    You have to stick with "most of the time in normal conditions you will get 20-60ms accuracy" (consider the difference between resolution and stability of the rate). But you can compensate for "lost frames" by using adaptive timers (and even skipping rendering frames to catch up) - in reality redrawing framerate is not important at all (as long as it's over 16fps so that your eye can perceive it as animation - the brain will interpolate properly) - it is important that the logic is updated fluently (to prevent the game from "lagging behind") which is completely enough in your case. You can even adapt the complexity of scene rendering to compensate lags. Remember that computer graphics is mostly about cheating.

    And to stress again - using another thread will only make things worse as the system will have to context-switch between threads thus losing more time (for a moment ignoring the fact you can't paint from worker threads in Qt) doing completely nothing from your application's point of view. You can use sleep/msleep/nanosleep in the main thread just as well but it won't change the fact that these functions only guarantee that you will not be woken before the given time elapses, nothing more.
    Thanks, so in your opinion the only solution is to implement an adaptative timer. I will try it right now.

    By the way: What happens if render takes more than 20 ms? 20-now.elapsed() would be a negative value. Should I control that case and pass a 0 to 20-now.elapsed()?




    @faldżip: I don't understand you very well, what do you mean exactly? Maybe this:

    Qt Code:
    1. MyQGLWidget::doFPSTest() {
    2. ...
    3. // draw 1000 frames or so
    4. while (1000 frames not drawn)
    5. {
    6. this->updateScene(); // rotate, translate, etc.
    7. this->updateGL(); // eventually calls paintGL()
    8. // put your time measurement somewhere in between
    9. ...
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ricardo; 12th August 2009 at 11:06.

  25. #17
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    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 ricardo View Post
    @faldżip: I don't understand you very well, what do you mean exactly? Maybe this:

    Qt Code:
    1. MyQGLWidget::doFPSTest() {
    2. ...
    3. // draw 1000 frames or so
    4. while (1000 frames not drawn)
    5. {
    6. this->updateScene(); // rotate, translate, etc.
    7. this->updateGL(); // eventually calls paintGL()
    8. // put your time measurement somewhere in between
    9. ...
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    That's what I meant :] Just to see how many FPS you can achieve when you start render of the frame just after you finish rendering prevoius one - so that's the while() what you wrote.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  26. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    Quote Originally Posted by ricardo View Post
    Thanks, so in your opinion the only solution is to implement an adaptative timer. I will try it right now.
    No, it's not a solution. But it will give better results than a static timeout timer.

    By the way: What happens if render takes more than 20 ms? 20-now.elapsed() would be a negative value. Should I control that case and pass a 0 to 20-now.elapsed()?
    Either use 0 or immediately calculate the next frame (and skip rendering it).

    But first see how many frames per second can your application obtain as faldżip suggested.
    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.


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

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

    Hi wysota.
    After implementing an adaptative timer as you told to me, I get some good results but also a strange result.


    3 Tests (3 times each one). 10 seconds every one:


    Code:
    Qt Code:
    1. void CEditor::TimerFired() {
    2. if (m_time.elapsed()>10000) {
    3. ChangeEditorState(EDITING);
    4. } else {
    5. QTime now;
    6. now.start();
    7. m_current_level->Update(0);
    8. m_gl_drawer->updateGL();
    9. m_rendered_frames++;
    10. int next_shot;
    11. if (SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed()<0) {
    12. next_shot=0;
    13. } else {
    14. next_shot=SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed();
    15. }
    16. QTimer::singleShot(next_shot, this, SLOT(TimerFired()));
    17. }
    18. }
    19.  
    20. // Start button
    21. m_time.start();
    22. m_rendered_frames=0;
    23. QTimer::singleShot(0, this, SLOT(TimerFired()));
    24.  
    25. // When ChangeEditorState(EDITING);
    26. float fps=m_rendered_frames/10.0;
    27. QString m=QString("FPS: %1. rendered frames: %2. Timer interval (ms): %3.").arg(fps).arg(m_rendered_frames).arg(SIMULATION_UPDATE_INTERVAL_IN_MS);
    28. QMessageBox::warning(this, "Warning", m);
    To copy to clipboard, switch view to plain text mode 


    Results under the same conditions (3 times each one, 9 tests):
    If SIMULATION_UPDATE_INTERVAL_IN_MS=10. FPS: 92.7. Expected 100 FPS.
    If SIMULATION_UPDATE_INTERVAL_IN_MS=20. FPS: 32. Expected 50 FPS.
    If SIMULATION_UPDATE_INTERVAL_IN_MS=30. FPS: 32. Expected 33.3 FPS.

    What is really strange is when SIMULATION_UPDATE_INTERVAL_IN_MS=20. I don't understand why I don't get 50 FPS.
    Any idea? Is my adaptative timer implemented properly? Should I use high res windows timer and round its result or QTime is fine?

    Thanks a lot, very helpful your help.


    EDIT: I realised (SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed()<0) never happens, so I'm still more disconcerted about interval=20, and next_shot is usually 20, so my computer updates and render it ultra fast. My conclusion is that Qt is taking a lot of time for it. Does anyone know anything about this? Thanks.
    Last edited by ricardo; 12th August 2009 at 12:50.

  28. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: 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.


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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.