mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-10 06:14:07 +08:00
feat: add display for fps
This commit is contained in:
14
src/main.cpp
14
src/main.cpp
@@ -27,8 +27,11 @@ float aspect;
|
|||||||
glm::mat4 p_mat, v_mat, m_mat, mv_mat;
|
glm::mat4 p_mat, v_mat, m_mat, mv_mat;
|
||||||
float inc = 0.01f;
|
float inc = 0.01f;
|
||||||
float tf = 0.0f;
|
float tf = 0.0f;
|
||||||
double last_time = 0.0f;
|
double last_time = glfwGetTime();
|
||||||
double delta_time = 0.0f;
|
double delta_time = 0.0f;
|
||||||
|
double fps_time_count = 0.0f;
|
||||||
|
int frame_count = 0;
|
||||||
|
int fps;
|
||||||
GLuint texture_array;
|
GLuint texture_array;
|
||||||
Camera camera;
|
Camera camera;
|
||||||
TextureManager texture_manager;
|
TextureManager texture_manager;
|
||||||
@@ -151,6 +154,15 @@ void render_sky() {
|
|||||||
void display(GLFWwindow* window, double current_time) {
|
void display(GLFWwindow* window, double current_time) {
|
||||||
delta_time = current_time - last_time;
|
delta_time = current_time - last_time;
|
||||||
last_time = current_time;
|
last_time = current_time;
|
||||||
|
fps_time_count += delta_time;
|
||||||
|
frame_count++;
|
||||||
|
if (fps_time_count >= 1.0f) {
|
||||||
|
fps = static_cast<int>(frame_count / fps_time_count);
|
||||||
|
std::string title = "Cubed FPS: " + std::to_string(fps);
|
||||||
|
glfwSetWindowTitle(window, title.c_str());
|
||||||
|
frame_count = 0;
|
||||||
|
fps_time_count = 0.0f;
|
||||||
|
}
|
||||||
world.update(delta_time);
|
world.update(delta_time);
|
||||||
camera.update_move_camera();
|
camera.update_move_camera();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user