zoukankan      html  css  js  c++  java
  • 27. 计算FPS

    // FPS info.
    // FPS相关变量
    int g_fps = 0; // FPS帧率值
    char g_fpsStr[16] = {0}; // 存放帧率值
    float g_time = 0.0f; // 系统运行时间
    float g_lastTime = 0.0f; // 持续的时间


    // 计算帧率
    void GetFPS()
    {

    // Get the second in millisecond then multiply it to convert to seconds.
    // g_time获取操作系统启动到现在所经过的毫秒数,乘以0.001f得到秒数
    g_time = GetTickCount() * 0.001f;


    // If time - last time is > than 1, save fpt.
    // 持续时间是否大于1秒
    if(g_time - g_lastTime > 1.0f)
    {
    // Record last time.
    // 记录新的持续时间
    g_lastTime = g_time;

    // Save FPS.
    // 把整数g_fps格式化为一个字符串保存在g_fpsStr中,并输出该字符串
    sprintf(g_fpsStr, "FPS: %d", g_fps);

    // Reset the FPS counter.
    // 重置帧率值为0
    g_fps = 0;
    }
    else
    {
    // Add to the frames per second.
    // 帧率值递增
    g_fps++;
    }
    }

      计算帧率是很简单的数学计算。程序中每处理一帧,计数器变量的值就加1。一旦经过1秒,就可以得到计数器的值并将其显示在屏幕上。只需做少量工作就可以让程序具备这样的功能。

  • 相关阅读:
    Sql Server截断日志(转)
    C#/VB.NET语法的比较(转)
    ReportViewer矩阵报表
    逐步学习 iPhone App 开发(1)
    一月二十四日,无家可归
    再见2009
    poj 1376 机器人广搜
    hdu 1004 颜色问题
    hdu 2734 简单地字符串处理
    1116 贪婪的送礼者
  • 原文地址:https://www.cnblogs.com/kex1n/p/2160151.html
Copyright © 2011-2022 走看看