窗口标题GLFW中的FPS计数器



我正在尝试让我的每秒帧数读数出现在我的窗口标题中。我以前做过一次,但是我将如何设置代码来做到这一点? 我需要从浮点数切换到常量字符*。

一个简单的方法,并使其与每个数字兼容,可以是:

#include <sstream>
template<class T>
char* toChar(T t) {
    std::ostringstream oss;
    oss << t;
    return oss.str().c_str();
}

这样,无论你使用 int、float、long 还是其他任何东西,它都可以工作并将其作为 char* 字符串返回。

您可以使用

istringstream然后str()然后c_str()

最新更新