相关疑难解决方法(0)

如何使用QueryPerformanceCounter?

我最近决定我需要为我的Timer类从使用毫秒更改为微秒,经过一些研究后,我认为QueryPerformanceCounter可能是我最安全的选择.(关于Boost::Posix它可能不适用于Win32 API 的警告让我有点失望).但是,我不确定如何实现它.

我正在做的是调用GetTicks()我正在使用的任何esque函数并将其分配给Timer的startingTicks变量.然后找到通过的时间量我只是从中减去函数的返回值startingTicks,当我重置计时器时,我再次调用该函数并为其分配startingTicks.不幸的是,从我看到的代码中,它并不像调用那么简单QueryPerformanceCounter(),而且我不确定我应该传递什么作为它的参数.

c++ windows timer

94
推荐指数
2
解决办法
17万
查看次数

得到毫秒的时间

我需要从计时器获得毫秒

    // get timer part
    time_t timer = time(NULL);
    struct tm now = *localtime( &timer );
    char timestamp[256];

    // format date time
    strftime(timestamp, sizeof(timestamp), "%Y-%m-%d_%H.%M.%S", &now);
Run Code Online (Sandbox Code Playgroud)

我希望在C#中得到这样的结果:

DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss.ff")
Run Code Online (Sandbox Code Playgroud)

我尝试使用%f或%F,但它确实适用于C++.如何从tm获得%f的毫秒数?

提前致谢

c++

12
推荐指数
4
解决办法
5万
查看次数

如何在OpenGL中计算FPS?

void CalculateFrameRate()
{    
    static float framesPerSecond    = 0.0f;       // This will store our fps
    static float lastTime   = 0.0f;       // This will hold the time from the last frame
    float currentTime = GetTickCount() * 0.001f;    
    ++framesPerSecond;
    if( currentTime - lastTime > 1.0f )
    {
        lastTime = currentTime;
        if(SHOW_FPS == 1) fprintf(stderr, "\nCurrent Frames Per Second: %d\n\n", (int)framesPerSecond);
        framesPerSecond = 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

我应该调用此函数void play(void)还是void display(void)

或者它没有任何区别?

c opengl playback

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×2

c ×1

opengl ×1

playback ×1

timer ×1

windows ×1