Results 1 to 5 of 5

Thread: QTimer Question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: QTimer Question

    I noticed that it works great. But only two problems. The FPS clock when putting in the titlebar is goes too quickly to even see it and when I disabled vsync in the nVidia control panel it only went to 1000 and thats it.

    Qt Code:
    1. #ifndef COMATIMER_HPP
    2. #define COMATIMER_HPP
    3.  
    4. #include "comaglobal.hpp"
    5. #include <QTime>
    6.  
    7. COMA_BEGIN_NAMESPACE
    8.  
    9. class COMA_DLL Timer
    10. {
    11. public:
    12. Timer()
    13. {
    14. reset();
    15. }
    16.  
    17. ~Timer()
    18. {
    19. }
    20.  
    21. void reset()
    22. {
    23. m_zeroClock = QTime::currentTime();
    24. m_startClock = QTime(0, 0, 0);
    25. }
    26.  
    27. ULong milliseconds()
    28. {
    29. QTime now = QTime::currentTime();
    30. return (now.second() - m_startClock.second()) * 1000 + (now.msec() - m_startClock.msec()) / 1000;
    31. }
    32. private:
    33. QTime m_zeroClock;
    34. QTime m_startClock;
    35.  
    36. };
    37.  
    38. COMA_END_NAMESPACE
    39.  
    40. #endif /*COMATIMER_HPP*/
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void
    2. ComaGL::paintGL()
    3. {
    4. ++g_fps;
    5. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    6. glLoadIdentity();
    7.  
    8. Vector3 eye(0.0, 0.0, -15.0);
    9. Vector3 centre(0.0, 0.0, 0.0);
    10. Vector3 up(0.0, 1.0, 0.0);
    11.  
    12. Matrix4 modelViewMatrix(Matrix4::M4_Identity);
    13. modelViewMatrix.lookAt(eye, centre, up);
    14.  
    15. glMultMatrixf(modelViewMatrix.data());
    16.  
    17. Matrix4 rot(Matrix4::M4_Identity);
    18. rot.rotateX(g_angle);
    19. glMultMatrixf(rot.data());
    20. glEnableClientState(GL_VERTEX_ARRAY);
    21. glEnableClientState(GL_COLOR_ARRAY);
    22.  
    23. glVertexPointer(3, GL_FLOAT, 0, &m_tri[0]);
    24. glColorPointer(3, GL_FLOAT, 0, &m_colour[0]);
    25. glDrawArrays(GL_QUADS, 0, 4);
    26.  
    27. glDisableClientState(GL_COLOR_ARRAY);
    28. glDisableClientState(GL_VERTEX_ARRAY);
    29.  
    30. g_angle += 2.0;
    31.  
    32. g_currentTime = g_timer.milliseconds();
    33. ULong time = g_currentTime - g_lastTime;
    34.  
    35. if(g_currentTime - g_lastTime > 1000)
    36. {
    37. setWindowTitle(QString("Fps: %1")
    38. .arg((UInt32)(g_fps / (Real)(g_currentTime - g_lastTime) * 1000.0)));
    39. g_lastTime = g_currentTime;
    40. g_fps = 0;
    41. }
    42. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ComaWhite; 1st August 2008 at 19:34.
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. Extending QTimer()
    By rishid in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2009, 01:59
  3. QThread/QObject and QTimer
    By swiety in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2008, 08:37
  4. Replies: 5
    Last Post: 6th March 2007, 05:34
  5. Question about using the QextSerialPort~
    By coffeemorphism in forum Qt Programming
    Replies: 2
    Last Post: 1st February 2007, 14:16

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