How to get the frame rate using wxGLCanvas library

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
shivam321
In need of some credit
In need of some credit
Posts: 2
Joined: Wed Mar 31, 2021 6:39 am

How to get the frame rate using wxGLCanvas library

Post by shivam321 »

Hi, I am new learner. I want to know about to How to get the frame rate using wxGLCanvas for linux environment? Have you any idea and code about it? Please help..
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to get the frame rate using wxGLCanvas library

Post by doublemax »

Use wxGetLocalTimeMillis to measure the time difference between two paint events. Then calculate FPS based on that.
https://docs.wxwidgets.org/trunk/group_ ... cd81ae09da

Alternatively, count frames over a longer period of time and calculate based on that.
Use the source, Luke!
shivam321
In need of some credit
In need of some credit
Posts: 2
Joined: Wed Mar 31, 2021 6:39 am

Re: How to get the frame rate using wxGLCanvas library

Post by shivam321 »

Can you explain using paint event how to work with video frame rate count
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to get the frame rate using wxGLCanvas library

Post by doublemax »

Supposed you have a paint event handler, do it like this:

Code: Select all

void SomeClass::OnPaint(wxPaintEvent &event)
{
  static wxLongLong s_lastTime = -1;
 
  wxLongLong actTime = ::wxGetLocalTimeMillis();
  double fps = 0.0f;

  if( s_lastTime != -1 ) {
    fps = 1000.0f / (actTime - s_lastTime).ToDouble();
  }
  s_lastTime = actTime;

  // your other rendering code
  
  // draw FPS on top 
};
This requires you to have some code that redraws the content permanently, e.g. by using one of the methods described in the wiki: https://wiki.wxwidgets.org/Making_a_render_loop
Use the source, Luke!
Post Reply