Brief Introduction to the FPS Calculation Method

Source: Internet
Author: User

FPSIt is the abbreviation of Frame per second, that is, the number of frames per second. This term is widely used in computer graphics, video collection, and games.

Here we will mainly introduce the Frame Rate in video games. The frame rate of the First person shooter game is only about 6 FPS, but it is still very successful. However, with the enhancement of the performance of hardware devices, especially video cards, the current frame rate of the game is generally 30FPS ~ Between 100FPS. Since the time consumed by each frame image is different, the frame rate is constantly changing, so each game will set a maximum frame rate to ensure smooth switching.

Next we will introduce the frame rate calculation using a piece of QT code.

// Timing...
Static QTime time;
Static int frames = 0;
Static bool started = false;

If (! Started | time. elapsed () & gt; 1000 ){
Qreal fps = frames * 1000./time. elapsed ();
If (fps = 0)
M_current_fps = "counting fps ...";
Else
M_current_fps = QString: fromLatin1 ("% 3 FPS"). arg (int) qRound (fps ));

Time. start ();
Started = true;
Frames = 0;

} Else {
++ Frames;

P. setOpacity (1 );
P. setFont (QFont ("times", 30 ));
P. fillRect (5, height ()-40,250, 40, Qt: white );
P. drawText (10, height ()-8, m_current_fps );
}
}

 

 

 

Generally, real-time games have a timer constantly refreshing images, so the output of each frame is completed through Calibri "lang =" en-US "> paintEvent. Put the above Code into the paintEvent to calculate the frame rate per second.

So how can we control the maximum frame rate?

In fact, it is also very simple, that is, by setting the interval of the timer, considering that the display frequency of the current display is generally 60 HZSimSun "lang =" zh-CN ">, therefore, interval is generally set to Calibri "lang =" en-US "> 1000/60 ms, that is, 60FPS is the theoretical maximum frame rate.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.