Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
Clock.cpp
Package: OpenGL动画演示(包含代码).rar [view]
Upload User: sz83729876
Upload Date: 2013-03-07
Package Size: 4140k
Code Size: 4k
Category:
OpenGL program
Development Platform:
Windows_Unix
- #include "Clock.h"
- //-------------------------------------------------------
- // Static variables
- //-------------------------------------------------------
- LARGE_INTEGER Timer::m_llPerformanceFreq;
- LARGE_INTEGER Timer::m_llBeginTime;
- LARGE_INTEGER Timer::m_llLastTime;
- LARGE_INTEGER Timer::m_llCurTime;
- float Timer::m_fTimeScale;
- float Timer::m_fBeginTime;
- float Timer::m_fCurrentTime;
- float Timer::m_fSecSinceLastFrame;
- float Timer::m_fCounter;
- float Timer::m_fFPS, Timer::m_fTempFPS;
- long Timer::m_dwFrameCount;
- //-------------------------------------------------------
- // Initialize()
- //-------------------------------------------------------
- // Checks performance counter for it's
- // frequency (if it exists) and resets the
- // counters.
- //
- bool Timer::Initialize()
- {
- if ( QueryPerformanceFrequency( &m_llPerformanceFreq ) )
- {
- QueryPerformanceCounter( &m_llBeginTime );
- m_llLastTime.QuadPart = m_llBeginTime.QuadPart;
- m_llCurTime.QuadPart = m_llBeginTime.QuadPart;
- m_fTimeScale = 1.0f / m_llPerformanceFreq.QuadPart;
- m_fBeginTime = m_llBeginTime.QuadPart * m_fTimeScale;
- m_fCurrentTime = m_llBeginTime.QuadPart * m_fTimeScale;
- m_fSecSinceLastFrame = 0.0f;
- m_fCounter = 0.0f;
- m_fFPS = 0.0f;
- m_fTempFPS = 0.0f;
- m_dwFrameCount = 0;
- return true;
- }
- return false;
- }
- //-------------------------------------------------------
- // GetTimer()
- //-------------------------------------------------------
- // Retrieves one of the four timer values.
- //
- // TIMER_APPSTART
- // Returns the time when the app started.
- //
- // TIMER_SINCEAPPSTART
- // Returns the time elapsed since the
- // app started.
- //
- // TIMER_SINCELASTFRAME
- // Returns the time it took the to render
- // the last frame.
- //
- // TIMER_ACTUAL
- // Returns the *actual* time at the moment
- // GetTimer() is called.
- //
- float Timer::GetTimer( TIMER_TYPE enumType )
- {
- LARGE_INTEGER ct;
- switch( enumType )
- {
- case TIMER_APPSTART:
- return m_fBeginTime;
- case TIMER_SINCEAPPSTART:
- return m_fCurrentTime;
- case TIMER_SINCELASTFRAME:
- return m_fSecSinceLastFrame;
- case TIMER_ACTUAL:
- QueryPerformanceCounter( &ct );
- return ( (ct.QuadPart-m_llBeginTime.QuadPart) * m_fTimeScale );
- }
- return -1.0f;
- }
- //-------------------------------------------------------
- // OncePerFrameQuery()
- //-------------------------------------------------------
- // Called once per frame to get the current
- // time and calculate the fps and other things
- // from that.
- //
- bool Timer::OncePerFrameQuery( HWND hWnd )
- {
- m_llLastTime = m_llCurTime;
- if (!QueryPerformanceCounter( &m_llCurTime ))
- return false;
- m_fCurrentTime = (float)( (m_llCurTime.QuadPart-m_llBeginTime.QuadPart) * m_fTimeScale );
- m_fSecSinceLastFrame = (float)( (m_llCurTime.QuadPart-m_llLastTime.QuadPart) * m_fTimeScale );
- m_fFPS = 1.0f / m_fSecSinceLastFrame;
- m_dwFrameCount++;
- m_fCounter += m_fSecSinceLastFrame;
- if ( m_fCounter>= 1.0f )
- {
- char ss[128];
- sprintf( ss, "The Hollow %1.2f fps running %1.2f seconds", m_fFPS, m_fCurrentTime );
- SetWindowText( hWnd, ss );
- m_fCounter = 0.0f;
- }
- return true;
- }
- //-------------------------------------------------------
- // OncePerFrameQuery()
- //-------------------------------------------------------
- // Returns the current frames per second.
- //
- float Timer::GetFPS()
- {
- return m_fFPS;
- }