- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在 native Windows OpenGL C++ 中获得准确帧率(每秒帧数)的好方法是什么?
最佳答案
这是我以前在 ATL 项目中使用的一个计时器类。有一段时间没有使用 C++ 或 opengl,但也许这会给你一些想法:
// Put this in your class somewhere
CTimer m_timer;
// Initialize the timer using
m_timer.Init();
// Call this everytime you call draw your scene
m_timer.Update();
// Call this to get the frames/sec
m_timer.GetFPS();
// Timer.h: Timer class used for determining elapsed time and
// frames per second.
//
//////////////////////////////////////////////////////////////////////
#ifndef _E_TIMER_H
#define _E_TIMER_H
#pragma once
//////////////////////////////////////////////////////////////////////
// INCLUDES
//////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <stdio.h>
#include <math.h>
//////////////////////////////////////////////////////////////////////
// CLASSES
//////////////////////////////////////////////////////////////////////
class CTimer
{
private:
//performance timer variables
__int64 m_i64PerformanceTimerStart;
__int64 m_i64PerformanceTimerElapsed;
//multimedia timer variables
unsigned long m_ulMMTimerElapsed;
unsigned long m_ulMMTimerStart;
//general timer variables
__int64 m_i64Frequency;
float m_fResolution;
bool m_bPerformanceTimer;
//FPS variables
float m_fTime1;
float m_fTime2;
float m_fDiffTime;
float m_fFPS;
int m_iFramesElapsed;
public:
//----------------------------------------------------------
// Name: CTimer::CTimer
// Desc: Default constructor
// Args: None
// Rets: None
//----------------------------------------------------------
CTimer( void )
: m_fFPS(0.0f), m_fTime1(0.0f), m_fTime2(0.0f), m_fDiffTime(0.0f), m_iFramesElapsed(0)
{ }
//----------------------------------------------------------
// Name: CTimer::CTimer
// Desc: Default destructor
// Args: None
// Rets: None
//----------------------------------------------------------
virtual ~CTimer( void )
{ }
//----------------------------------------------------------
// Name: CTimer::Init - public
// Desc: Initiate the timer for the program
// Args: None
// Rets: bool: -true: using performance timer
// -false: using multimedia timer
//----------------------------------------------------------
bool Init( void )
{
//check to see if we are going to be using the performance counter
if( QueryPerformanceFrequency( ( LARGE_INTEGER* )&m_i64Frequency ) )
{
//we are able to use the performance timer
m_bPerformanceTimer= true;
//get the current time and store it in m_i64PerformanceTimerStart
QueryPerformanceCounter( ( LARGE_INTEGER* )&m_i64PerformanceTimerStart );
//calculate the timer resolution
m_fResolution= ( float )( ( ( double )1.0f )/( ( double )m_i64Frequency ) );
//initialize the elapsed time variable
m_i64PerformanceTimerElapsed= m_i64PerformanceTimerStart;
}
//we cannot use the performence counter, so we'll use the multimedia counter
else
{
//we're using the multimedia counter
m_bPerformanceTimer= false;
m_ulMMTimerStart = timeGetTime( ); //record the time the program started
m_ulMMTimerElapsed = m_ulMMTimerStart; //initialize the elapsed time variable
m_fResolution = 1.0f/1000.0f;
m_i64Frequency = 1000;
}
return m_bPerformanceTimer;
}
//----------------------------------------------------------
// Name: CTimer::Update - public
// Desc: Update the timer (perform FPS counter calculations)
// Args: None
// Rets: None
//----------------------------------------------------------
void Update( void )
{
//increase the number of frames that have passed
m_iFramesElapsed++;
if ( m_iFramesElapsed % 5 == 1 )
m_fTime1 = GetTime( )/1000;
else if ( m_iFramesElapsed % 5 == 0 )
{
m_fTime1 = m_fTime2;
m_fTime2 = GetTime( )/1000;
m_fDiffTime= ( float )fabs( m_fTime2-m_fTime1 );
}
m_fFPS= 5/( m_fDiffTime );
/*m_fTime2 = GetTime( )/1000;
m_fDiffTime= ( float )fabs( m_fTime2-m_fTime1 );
if (m_fDiffTime > 1.0f)
{
m_fTime1 = m_fTime2;
m_fFPS= m_iFramesElapsed / ( m_fDiffTime );
m_iFramesElapsed = 0;
}
*/
}
//----------------------------------------------------------
// Name: CTimer::GetTime - public
// Desc: Get the current time since the program started
// Args: None
// Rets: float: The time elapsed since the program started.
//----------------------------------------------------------
float GetTime( void )
{
__int64 i64Time;
//check to see if we are using the performance counter
if( m_bPerformanceTimer )
{
//get the current performance time
QueryPerformanceCounter( ( LARGE_INTEGER* )&i64Time );
//return the time since the program started
return ( ( float )( i64Time - m_i64PerformanceTimerStart )*m_fResolution )*1000.0f;
}
//we are using the multimedia counter
else
{
//return the time since the program started
return ( ( float )( timeGetTime( ) - m_ulMMTimerStart )*m_fResolution )*1000.0f;
}
}
//----------------------------------------------------------
// Name: CTimer::GetElapsedSeconds - public
// Desc: Get the elapsed seconds since the last frame was drawn.
// Args: elapsedFrames:
// Rets: float: The time elapsed since the program started.
//----------------------------------------------------------
float GetElapsedSeconds(unsigned long elapsedFrames = 1)
{ return m_fDiffTime; }
//----------------------------------------------------------
// Name: CTimer::GetFPS - public
// Desc: Get the current number of frames per second
// Args: None
// Rets: float: the number of frames per second
//----------------------------------------------------------
inline float GetFPS( void )
{ return m_fFPS; }
};
#endif // _E_TIMER_H
关于c++ - 如何在 OpenGL 中捕捉准确的帧率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2160054/
我使用 QBFC v13 和 Delphi XE6。 目标是从我的应用程序创建 Estimate 并将其参数设置到 QuickBooks 中。 我从 QBFC13 导入类型库并将其添加到我的项目中。
我有一个数据库,其中有很多格式不正确的地址。在这个地址中,我只有一个街道地址或带有城市名称的街道。在我的应用程序中,用户选择一些类别,然后我想在 map 上显示例如 50,100,300 等地址。(不
在大多数软件项目中,缺陷源自需求、设计、编码和缺陷更正。根据我的经验,大多数缺陷都源于编码阶段。 我有兴趣了解软件开发人员使用哪些实用方法来降低缺陷注入(inject)率。 我已经看到以下方法的使用取
我正在使用实时 API 中的标签订阅构建一个应用程序,并且有一个与容量规划相关的问题。我们可能有大量用户同时发布到订阅的主题标签,因此问题是 API 实际发布到我们的订阅处理端点的频率是多少?例如,如
尝试使用 NULLIF 或 IFNULL 函数,但仍收到被零除的消息。 SELECT client_id ,COUNT(distinct CASE WHEN status = 'failed' THE
我目前正在开发一个使用 Django-rest-framework 制作的 API。我必须根据每个用户组设置限制率。 我们目前使用默认配置的 memcached 作为缓存后端,即按站点缓存。 在使用
我认为有时在神经网络(特别是一般对抗网络)训练期间改变丢失率可能是一个好主意,从高丢失率开始,然后线性地将丢失率降低到零。您认为这有意义吗?如果是的话,是否有可能在 tensorflow 中实现这一点
我有一个 Windows Server 2008,Plesk 运行着两个网站。有时服务器运行缓慢,并且有一个 named.exe 进程使 CPU 峰值达到 100%。它持续很短的时间,过一会儿它又来了
我正在使用 scikit-learn 随机森林分类器,我想通过将成功投票所需的树数量从大于 50% 增加到 75% 来降低 FP 率,在阅读文档后我不这样做确定如何做到这一点。有没有人有什么建议。 (
当我连续按下按键事件(字母 k)时,为什么以下按键事件不会减慢 3000 密耳?如果我按住手指,计数会迅速增加,因为 mcount 上没有 setTimeout。这是为什么?每次计数之间应该有延迟,但
我是一名优秀的程序员,十分优秀!